C# 如何删除默认的ASP.NET核心标识终结点?
假设我想编写自己的登录、注销端点及其视图 但出于某种原因,我正在努力删除现有端点 每当我删除可能与这些端点相关的内容时,它们都会重新创建自己并返回默认视图 基本上,我希望删除尽可能多的从ASP.NET核心标识生成的默认端点/视图 我怎么才能做到呢C# 如何删除默认的ASP.NET核心标识终结点?,c#,asp.net-core,asp.net-core-mvc,asp.net-identity,C#,Asp.net Core,Asp.net Core Mvc,Asp.net Identity,假设我想编写自己的登录、注销端点及其视图 但出于某种原因,我正在努力删除现有端点 每当我删除可能与这些端点相关的内容时,它们都会重新创建自己并返回默认视图 基本上,我希望删除尽可能多的从ASP.NET核心标识生成的默认端点/视图 我怎么才能做到呢 "Templates/Identity/Pages/Account/Account.AccessDenied.cs.cshtml", "Templates/Identity/Pages/Account/Account.A
"Templates/Identity/Pages/Account/Account.AccessDenied.cs.cshtml",
"Templates/Identity/Pages/Account/Account.AccessDenied.cshtml",
"Templates/Identity/Pages/Account/Account.ConfirmEmail.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ConfirmEmail.cshtml",
"Templates/Identity/Pages/Account/Account.ExternalLogin.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ExternalLogin.cshtml",
"Templates/Identity/Pages/Account/Account.ForgotPassword.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ForgotPassword.cshtml",
"Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cshtml",
"Templates/Identity/Pages/Account/Account.Lockout.cs.cshtml",
"Templates/Identity/Pages/Account/Account.Lockout.cshtml",
"Templates/Identity/Pages/Account/Account.Login.cs.cshtml",
"Templates/Identity/Pages/Account/Account.Login.cshtml",
"Templates/Identity/Pages/Account/Account.LoginWith2fa.cs.cshtml",
"Templates/Identity/Pages/Account/Account.LoginWith2fa.cshtml",
"Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cs.cshtml",
"Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cshtml",
"Templates/Identity/Pages/Account/Account.Logout.cs.cshtml",
"Templates/Identity/Pages/Account/Account.Logout.cshtml",
"Templates/Identity/Pages/Account/Account.Register.cs.cshtml",
"Templates/Identity/Pages/Account/Account.Register.cshtml",
"Templates/Identity/Pages/Account/Account.ResetPassword.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ResetPassword.cshtml",
"Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cs.cshtml",
"Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cshtml",
"Templates/Identity/Pages/Account/Account._ViewImports.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ManageNavPages.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cs.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage._Layout.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage._ManageNav.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage._StatusMessage.cshtml",
"Templates/Identity/Pages/Account/Manage/Account.Manage._ViewImports.cshtml",
(...)
您不能使用
AddDefaultIdentity
,因为在内部,这会调用AddDefaultUI
,其中包含您不需要的Razor页面“端点”。您需要使用AddIdentity
或AddIdentityCore
。您不能使用AddDefaultIdentity
,因为在内部,这会调用AddDefaultUI
,其中包含您不想要的Razor页面“端点”。您需要使用附加属性
或附加属性核心
。我检查了ASPNET的Github上的源代码,并对其进行了一些编辑
public static IdentityBuilder AddDefaultIdentity(此IServiceCollection服务,操作配置选项),其中TUser:class
{
services.AddAuthentication(o=>
{
o、 DefaultScheme=IdentityConstants.ApplicationScheme;
o、 DefaultSignInScheme=IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o=>{});
退货服务。AddIdentityCore(o=>
{
o、 Stores.MaxLengthForKeys=128;
配置选项?.Invoke(o);
})
.AddDefaultUI()//它将被删除
.AddDefaultTokenProviders();
}
代码如下:
扩展方法:
public static class IServiceCollectionExtensions
{
public static IdentityBuilder AddCustomDefaultIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> configureOptions) where TUser : class
{
services.AddAuthentication(o =>
{
o.DefaultScheme = IdentityConstants.ApplicationScheme;
o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o => { });
return services.AddIdentityCore<TUser>(o =>
{
o.Stores.MaxLengthForKeys = 128;
configureOptions?.Invoke(o);
})
.AddDefaultTokenProviders();
}
}
公共静态类IServiceCollectionExtensions
{
public static IdentityBuilder AddCustomDefaultIdentity(此IServiceCollection服务,操作配置选项),其中TUser:class
{
services.AddAuthentication(o=>
{
o、 DefaultScheme=IdentityConstants.ApplicationScheme;
o、 DefaultSignInScheme=IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o=>{});
退货服务。AddIdentityCore(o=>
{
o、 Stores.MaxLengthForKeys=128;
配置选项?.Invoke(o);
})
.AddDefaultTokenProviders();
}
}
Startup.cs
services.AddCustomDefaultIdentity<User>
(
o => { /* options e.g */ o.Password.RequireDigit = true;}
)
.AddSignInManager()
.AddEntityFrameworkStores<Context>();
services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "some_value";
options.Cookie.Name = "some_value";
options.Cookie.HttpOnly = some_value;
options.ExpireTimeSpan = TimeSpan.FromMinutes(some_value);
options.LoginPath = "some_value";
options.LogoutPath = "some_value";
options.ReturnUrlParameter = CookieAuthenticationDefaults.some_value;
options.SlidingExpiration = some_value;
});
services.AddCustomDefaultIdentity
(
o=>{/*选项,例如*/o.Password.RequireDigit=true;}
)
.AddSignInManager()的名称
.AddEntityFrameworkStores();
services.configureApplicationOK(选项=>
{
options.AccessDeniedPath=“某些值”;
options.Cookie.Name=“某些值”;
options.Cookie.HttpOnly=某些_值;
options.ExpireTimeSpan=TimeSpan.FromMinutes(某些值);
options.LoginPath=“某些值”;
options.LogoutPath=“某些值”;
options.ReturnUrlParameter=CookieAuthenticationDefaults.some_值;
options.SlidingExpiration=某些值;
});
我检查了ASPNET的Github上的源代码,并对其进行了一些编辑
public static IdentityBuilder AddDefaultIdentity(此IServiceCollection服务,操作配置选项),其中TUser:class
{
services.AddAuthentication(o=>
{
o、 DefaultScheme=IdentityConstants.ApplicationScheme;
o、 DefaultSignInScheme=IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o=>{});
退货服务。AddIdentityCore(o=>
{
o、 Stores.MaxLengthForKeys=128;
配置选项?.Invoke(o);
})
.AddDefaultUI()//它将被删除
.AddDefaultTokenProviders();
}
代码如下:
扩展方法:
public static class IServiceCollectionExtensions
{
public static IdentityBuilder AddCustomDefaultIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> configureOptions) where TUser : class
{
services.AddAuthentication(o =>
{
o.DefaultScheme = IdentityConstants.ApplicationScheme;
o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o => { });
return services.AddIdentityCore<TUser>(o =>
{
o.Stores.MaxLengthForKeys = 128;
configureOptions?.Invoke(o);
})
.AddDefaultTokenProviders();
}
}
公共静态类IServiceCollectionExtensions
{
public static IdentityBuilder AddCustomDefaultIdentity(此IServiceCollection服务,操作配置选项),其中TUser:class
{
services.AddAuthentication(o=>
{
o、 DefaultScheme=IdentityConstants.ApplicationScheme;
o、 DefaultSignInScheme=IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o=>{});
退货服务。AddIdentityCore(o=>
{
o、 Stores.MaxLengthForKeys=128;
配置选项?.Invoke(o);
})
.AddDefaultTokenProviders();
}
}
Startup.cs
services.AddCustomDefaultIdentity<User>
(
o => { /* options e.g */ o.Password.RequireDigit = true;}
)
.AddSignInManager()
.AddEntityFrameworkStores<Context>();
services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "some_value";
options.Cookie.Name = "some_value";
options.Cookie.HttpOnly = some_value;
options.ExpireTimeSpan = TimeSpan.FromMinutes(some_value);
options.LoginPath = "some_value";
options.LogoutPath = "some_value";
options.ReturnUrlParameter = CookieAuthenticationDefaults.some_value;
options.SlidingExpiration = some_value;
});
services.AddCustomDefaultIdentity
(
o=>{/*选项,例如*/o.Password.RequireDigit=true;}
)
.AddSignInManager()的名称
.AddEntityFrameworkStores();
services.configureApplicationOK(选项=>
{
options.AccessDeniedPath=“某些值”;
options.Cookie.Name=“某些值”;
options.Cookie.HttpOnly=某些_值;
options.ExpireTimeSpan=TimeSpan.FromMinutes(某些值);
options.LoginPath=“某些值”;
options.LogoutPath=“某些值”;
options.ReturnUrlParameter=CookieAuthenticationDefaults.some_值;
options.SlidingExpiration=某些值;
});
我想如果不进行配置,就不可能进行AddIdentityCore。AddAuthentication challenge and signin manager,是吗?:派斯。正如名称所示,它只是添加了标识的核心内容。您可能想改用AddIdentity。如果您很好奇或有更好的想法,那么我在下面发布了适合我的代码(基于您的想法),我想不需要配置就不可能执行AddIdentity Core。AddAuthentication challenge and signin manager,是吗?:派斯。正如名称所示,它只是添加了标识的核心内容。你可能想用AddIdentity来代替。如果你好奇或者有更好的想法,那么下面我发布了适合我的代码(基于你的想法)