现在我花了将近一个星期的时间在IdentityUser类中
我是新的asp.net核心的原因,或者没有遇到类似的情况,
在链接上应用课程时:
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-enable-qrcodes?view=aspnetcore-2.1
找不到文件:EnableAuthenticator.cshtml
(Microsoft.AspNetCore.Identity)是生成视图文件的人,但是这里的问题是,是否可以通过任何方式找到此文件。请注意,newProject> asp.netCore MVC创建的具有身份验证的应用程序。
C:\ WebApplicationCore \ WebApplicationCore \ Views \ Shared_LoginPartial.cshtml
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
@if (SignInManager.IsSignedIn(User))
{
<form asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })" method="post" id="logoutForm" class="navbar-right">
<ul class="nav navbar-nav navbar-right">
<li>
<a asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
</li>
<li>
<button type="submit" class="btn btn-link navbar-btn navbar-link">Logout</button>
</li>
</ul>
</form>
}
else
{
<ul class="nav navbar-nav navbar-right">
<li><a asp-area="Identity" asp-page="/Account/Register">Register</a></li>
<li><a asp-area="Identity" asp-page="/Account/Login">Login</a></li>
</ul>
}
请注意,所需页面出现在浏览器中
https://本地主机:**** /身份/帐户/管理/ EnableAuthenticator
该文件在项目文件夹中根本不存在,可以查找和编辑。
如果您难以控制问题,我深表歉意,因为我
使用Google翻译
最佳答案
当我们创建带有个人身份验证的ASP.NET Core MVC应用程序时,帐户管理视图和/或页面将被隐藏。
他们在哪?它们是ASP.NET Core Identity包中的已编译视图/页面;我们可以在GitHub存储库中看到它们。例如,这是EnableAuthenticator page。
要在我们的项目中显示这些页面,我们需要to scaffold Identity。这是从dotnet命令行界面执行操作的方法。
假定使用ASP.NET Core 2.1.0(通过dotnet --info
检查)。
// create a new app
dotnet new mvc --auth Identity
// install the code generator tool
dotnet tool install -g dotnet-aspnet-codegenerator --version 2.1.0
// add the code generation package
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 2.1.0
dotnet restore
// generate the enable authenticator file
dotnet aspnet-codegenerator identity --files Account.Manage.EnableAuthenticator
我们还可以生成许多其他文件。
// view the help
dotnet aspnet-codegenerator identity -h
// list the available files to generate
dotnet aspnet-codegenerator identity --listFiles