ASP.Net core MVC6 Redirect to Login when not authorised

前端 未结 4 656
南旧
南旧 2021-01-13 20:25

I am using ASP.Net core MVC 6, I am trying to get the user redirected to the login page if they are not authenticated.

I cant seem to get it to work, currently the u

4条回答
  •  自闭症患者
    2021-01-13 21:16

    OK, as of Asp.Net Core 2.1 . In order to redirect user to login page. this is what you need to do in ConfigureServices(IserviceCollection services) method.

    services.ConfigureApplicationCookie(options =>
    {
        options.LoginPath = "/Identity/Account/Login";
        options.SlidingExpiration = true;
    });
    

    for more info visit Microsoft identity documentation. https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-configuration?view=aspnetcore-2.1#cookie-settings

提交回复
热议问题