My ASP.NET Core app requires users to login. I created a public action method that allows anonymous users i.e.
[AllowAnonymous] public IActionResult Public() { return View(); }
Because in my Startup.cs I require authentication, users are automatically redirected to the login page.
I want to change the behavior and redirect users to the public page automatically and let them click a link to login.
How do I redirect my users to the public page instead of the login page?
1 Answers
Answers 1
Just change default mapping in App_Start:
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters* new { controller = "Public", action = "Public", id = UrlParameter.Optional } );
UPDATE
After your comment I think this will answer your needs:
services.Configure<IdentityOptions>(options => { options.Cookies.ApplicationCookie.LoginPath = new PathString("/Home/Public"); });
Add it to the ConfigureServices
method in Startup.cs
0 comments:
Post a Comment