如何在 ASP NET Core 2.2.0+ 中禁用注册表单?
只是为了获取和删除适当的模型,我不能,因为它不在项目中,根据文档,我知道这与“ConfigureApplicationPartManager”之类的东西有关
链接在这里
但我找不到合适的例子来禁用它
目标是禁用新用户的注册,只留下登录\密码表单
services.AddMvc()
.ConfigureApplicationPartManager(x =>
{
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var relatedParts = relatedAssemblies.ToDictionary(
ra => ra,
CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts);
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Run Code Online (Sandbox Code Playgroud)
Mar*_*dok 20
另一种选择是删除注册链接并在 Startup 类中从注册重定向到登录:
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
endpoints.MapPost("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
});
Run Code Online (Sandbox Code Playgroud)
Nie*_* R. 12
您可以指定要搭建脚手架的部件。以下是 ASP.NET Core 文档的摘录。链接到下面的来源。
要禁用用户注册:
dotnet aspnet-codegenerator identity -dc RPauth.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.RegisterConfirmation"
Run Code Online (Sandbox Code Playgroud)
public class RegisterModel : PageModel
{
public IActionResult OnGet()
{
return RedirectToPage("Login");
}
public IActionResult OnPost()
{
return RedirectToPage("Login");
}
}
Run Code Online (Sandbox Code Playgroud)
@page
@model RegisterModel
@{
ViewData["Title"] = "Go to Login";
}
<h1>@ViewData["Title"]</h1>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Login">Login</a>
</li>
Run Code Online (Sandbox Code Playgroud)
@*
<p>
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
</p>
*@
Run Code Online (Sandbox Code Playgroud)
PageModel:[AllowAnonymous]
public class RegisterConfirmationModel : PageModel
{
public IActionResult OnGet()
{
return Page();
}
}
Run Code Online (Sandbox Code Playgroud)
来源:https : //docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio#disable-register-page
更多信息dotnet aspnet-codegenerator:https : //docs.microsoft.com/en-us/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator
| 归档时间: |
|
| 查看次数: |
4797 次 |
| 最近记录: |