'Change default Identity routes in an Angular & ASP.NET Core project
I configured Angular to use "login" route to show a LoginComponent
page. That's ok.
But when I try to access some authorized page without login made, I got the following address in browser:
https://localhost:5001/Identity/Account/Login?ReturnUrl=%2Fapi%2FMyController%2FMyAction
and this error:
The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration we have looked at it in the following locations:
/Areas/Identity/Pages/Account/_LoginPartial.cshtml
/Areas/Identity/Pages/_LoginPartial.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.cshtml
/Pages/Shared/_LoginPartial.cshtml
/Views/Shared/_LoginPartial.cshtml
Is it possible to point to /login page instead of /Identity/Account/Login
?
Solution 1:[1]
You can try to configure the app's cookie in Startup.ConfigureServices. ConfigureApplicationCookie
must be called after calling AddIdentity
or AddDefaultIdentity
:
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
});
Solution 2:[2]
from the api-authorization.module.ts file within the ClientApp.
Add { path: 'login', component: LoginComponent },
to the RouterModule.forChild([]) array.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nan Yu |
Solution 2 | chri3g91 |