asp.net 5 mvc 6 loginUrl change path

后端 未结 4 1036
死守一世寂寞
死守一世寂寞 2021-01-17 15:20

When creating a new project in VS 2015 WebApplication, how would you go about changing the Redirect LoginUrl Path when not Authorize\'d?

I have created a new Area, w

相关标签:
4条回答
  • 2021-01-17 15:34
    services.AddIdentity<ApplicationUser, IdentityRole>(options =>
    {
        options.Cookies.ApplicationCookie.LoginPath = "/Login";
    });
    

    This is basically the same as Jhonattan's answer, and it worked for me when the accepted answer didn't. The only difference is that if you don't have an ApplicationRole model, you can use IdentityRole (which ApplicationRole would inherit from).

    0 讨论(0)
  • 2021-01-17 15:38

    Try doing the following:

    services.Configure<CookieAuthenticationOptions>(options =>
    {
        options.LoginPath = new PathString("/<YOUR-AREA>/Account/Login");
    });
    

    Question: Did you decorate your controller with an [Area] attribute?

    0 讨论(0)
  • 2021-01-17 15:44
    services.ConfigureIdentityApplicationCookie(options => {
      options.LoginPath = "/AREA/Login/Index";
    });
    
    0 讨论(0)
  • 2021-01-17 15:53
    services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
    {
        options.Cookies.ApplicationCookie.LoginPath = "/Login";
    });
    
    0 讨论(0)
提交回复
热议问题