asp.net 核心 mvc 更改默认标识区域路由
asp.net core mvc change default Identity area routes
asp.net 核心 2.2 身份是通过
添加的
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
登录设置为“/Identity/Account/Login”:
options.LoginPath = "/Identity/Account/Login";
现在如何更改通过 Startup.cs 添加的身份区域的路由,例如:
https://www.example.com/admin instead of having https://www.example.com/identity/account/login
或
https://www.example.com/register 以便它转到 HomeController->RegisterAction。这将允许我捕获 HomeController->RegisterAction 并将其重定向到 HomeController->IndexAction,以便 禁用注册 。
如果有人搜索 asp.net core mvc 2.2 的答案:
当您调用 DefaultUI 时,您没有任何要修改的特定页面或控制器。
您必须脚手架您要修改的页面。
- 鼠标右键点击项目
- 添加 --> 新脚手架项目(如果禁用,停止 debugging/running)
- 在左侧select标识并点击添加
- Select 您的布局页面 (~/Views/Shared/_Layoutcshtml) 以获得正确的布局
- select 您要覆盖的页面,例如Account\Register
- Select 您的数据上下文 class(或通过单击 [+] 创建一个新的)
- 单击添加
现在您将在 /Areas/Identity/Pages/Account/Register.cshtml 中看到
展开Register.cshtml并打开文件Register.cshtml.cs。 ('codebehind')
现在如果你想禁用注册,你可以替换
public void OnGet(string returnUrl = null)
{
ReturnUrl = returnUrl;
}
与:
public IActionResult OnGet(string returnUrl = null) => RedirectToPage("/Account/Login"); // disable registrations
附加信息:
- https://github.com/aspnet/Identity/issues/1824
- https://github.com/aspnet/Docs/issues/10226
- https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio
万一 [MSFT] 正在阅读这篇文章:如果您可以通过 Startup.cs 禁用注册或更改重定向路由而无需脚手架(这将允许您更新软件包而无需 UI 您曾经在版本 x.
搭建过的脚手架
asp.net 核心 2.2 身份是通过
添加的services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
登录设置为“/Identity/Account/Login”:
options.LoginPath = "/Identity/Account/Login";
现在如何更改通过 Startup.cs 添加的身份区域的路由,例如:
https://www.example.com/admin instead of having https://www.example.com/identity/account/login
或
https://www.example.com/register 以便它转到 HomeController->RegisterAction。这将允许我捕获 HomeController->RegisterAction 并将其重定向到 HomeController->IndexAction,以便 禁用注册 。
如果有人搜索 asp.net core mvc 2.2 的答案:
当您调用 DefaultUI 时,您没有任何要修改的特定页面或控制器。
您必须脚手架您要修改的页面。
- 鼠标右键点击项目
- 添加 --> 新脚手架项目(如果禁用,停止 debugging/running)
- 在左侧select标识并点击添加
- Select 您的布局页面 (~/Views/Shared/_Layoutcshtml) 以获得正确的布局
- select 您要覆盖的页面,例如Account\Register
- Select 您的数据上下文 class(或通过单击 [+] 创建一个新的)
- 单击添加
现在您将在 /Areas/Identity/Pages/Account/Register.cshtml 中看到
展开Register.cshtml并打开文件Register.cshtml.cs。 ('codebehind')
现在如果你想禁用注册,你可以替换
public void OnGet(string returnUrl = null)
{
ReturnUrl = returnUrl;
}
与:
public IActionResult OnGet(string returnUrl = null) => RedirectToPage("/Account/Login"); // disable registrations
附加信息:
- https://github.com/aspnet/Identity/issues/1824
- https://github.com/aspnet/Docs/issues/10226
- https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio
万一 [MSFT] 正在阅读这篇文章:如果您可以通过 Startup.cs 禁用注册或更改重定向路由而无需脚手架(这将允许您更新软件包而无需 UI 您曾经在版本 x.
搭建过的脚手架