Redirect to login when unauthorized in ASP.NET Core

后端 未结 6 1284
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 06:24

In the previous ASP.NET MVC, there was an option to redirect to the login action, if the user was not authenticated.

I need the same thing with ASP.NET Core, so I:

6条回答
  •  生来不讨喜
    2020-12-14 07:10

    You can configure the path using CookieAuthenticationOptions class.

    Something like this.

    app.UseCookieAuthentication(new CookieAuthenticationOptions {
            LoginPath = new PathString("/Login/"),
            AuthenticationType = "My-Magical-Authentication",
            // etc...
            },
    });
    

提交回复
热议问题