要更改 ASP.NET Core 中的身份验证路径,需要在 Startup.cs 文件中添加以下代码:
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/MyLoginPath";
options.AccessDeniedPath = "/MyAccessDeniedPath";
});
将 MyLoginPath
和 MyAccessDeniedPath
替换为您想要的路径。
这将在应用程序中的所有身份验证方案中更改登录和拒绝访问路径。如果您只想更改某一个方案的路径,则可以在 ConfigureServices()
方法中使用具有方案名称的 Configure
方法。例如:
services.Configure(YourSchemeName, options =>
{
options.LoginPath = "/MyLoginPath";
options.AccessDeniedPath = "/MyAccessDeniedPath";
});