现在我在 IdentityUser 类中花了将近一周的时间 之所以我是asp.net core新手还是没有遇到类似的情况, 在链接上应用类(class)时: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-enable-qrcodes?view=aspnetcore-2.1 找不到文件:EnableAuthenticator.cshtml (Microsoft.AspNetCore.Identity) 是生成 View 文件的那个,但是这里的问题是你是否可以通过任何方式找到这个文件注意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://localhost:****/身份/账户/管理/EnableAuthenticator 该文件在项目文件夹中根本不存在,是否可以找到并编辑它。
I apologize if you have difficulty in containing the problem because I use Google translation
最佳答案
当我们创建带有个人身份验证的 ASP.NET Core MVC 应用程序时,帐户管理 View 和/或页面是隐藏的。
他们在哪里?它们是 ASP.NET Core Identity 包中的编译 View /页面;我们可以在 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
关于c# - 在哪里生成 SignInManager IdentityUser .cshtml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51621462/