I use Identity
in an Asp.net Core 5
project targeted .Net 5
. As you know when make a Controller
as Authorize
any user try to access any view
in the controller the Identity
will redirect him to the /Identity/Account/Login
razor page, so I created my own login controller with views.
The question: I wanna the unauthorized
users to redirected to my custom login
view, how can I do that?
What I tried: In ConfigureServices
method in Startup
class I added this piece of code:
services.AddAuthentication( CookieAuthenticationDefaults.AuthenticationScheme )
.AddCookie( options =>
{
options.LoginPath = "/Login";
} );
services.AddControllersWithViews();
But still not working the users still redirected to /Identity/Account/Login
and I wanna them riderected to my custom login view
.
In my case I replaced my old code with:
services.ConfigureApplicationCookie( options =>
{
options.LoginPath = "/Login";
} );
Thanks to Martin Costello
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.