![](/img/trans.png)
[英]Change default Identity routes in an Angular & ASP.NET Core project
[英]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";
现在我如何从Identity区域更改路由,这是通过Startup.cs添加的,以便我可以做例如:
https://www.example.com/admin而不是https://www.example.com/identity/account/login
要么
https://www.example.com/register,以便转到HomeController-> RegisterAction。 这将允许我捕获并将HomeController-> RegisterAction重定向到HomeController-> IndexAction 以禁用注册 。
如果有人搜索asp.net核心mvc 2.2的答案:
当您调用DefaultUI时,您没有要修改的任何特定页面或控制器。
你必须脚手架要修改的页面。
现在您将在/Areas/Identity/Pages/Account/Register.cshtml中看到
展开Register.cshtml并打开Register.cshtml.cs文件。 ( '代码隐藏')
现在,如果要禁用注册,可以替换
public void OnGet(string returnUrl = null)
{
ReturnUrl = returnUrl;
}
有:
public IActionResult OnGet(string returnUrl = null) => RedirectToPage("/Account/Login"); // disable registrations
附加信息:
如果任何[MSFT]正在读取这个 :如果您可以通过Startup.cs禁用注册或更改重定向路由而不必使用scaffold(这将允许您更新包而不必使用曾经在x版本搭建的UI)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.