AspNet Core 脚手架应用程序中的登录和注册页面在哪里? [英] Where are the Login and Register pages in an AspNet Core scaffolded app?

查看:31
本文介绍了AspNet Core 脚手架应用程序中的登录和注册页面在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VS 2017 中,我创建了一个新的 ASP.NET Core Web 应用程序.在向导的第二页上,我选择了 Web 应用程序,对于身份验证,我选择了个人用户帐户".

现在,我正在尝试查找与/Account/Register 和/Account/Login 关联的页面.

_Layout.cshtml 引入了 _LoginPartial.cshtml,就像它在经典 MVC 中所做的一样:

如果用户未登录,则 _LoginPartial 包含指向登录和注册页面的

我知道脚手架代码有效.当我运行项目时,注册链接指向/Identity/Account/Register",登录链接指向/Identity/Account/Login".单击注册"链接,我会看到一个包含创建新帐户"文本的注册页面.

但我找不到文本创建新帐户"项目中的任何位置.

有人能告诉我我错过了什么吗?

解决方案

在 asp.net core 2.1 预览版期间宣布,身份 UI 将移至新的 Razor 类库.https://blogs.msdn.microsoft.com/webdev/2018/03/02/aspnetcore-2-1-identity-ui/

如果您更喜欢本地视图,仍然可以将身份视图构建到您自己的项目中:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio

In VS 2017, I created a new ASP.NET Core Web Application. On the second page of the wizard, I chose Web Application, and for Authentication, I chose "Individual User Accounts".

Now, I'm trying to find the Pages associated with /Account/Register and /Account/Login.

_Layout.cshtml brings in _LoginPartial.cshtml, much as it did in classic MVC:

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
        <li><a asp-page="/Index">Home</a></li>
        <li><a asp-page="/About">About</a></li>
        <li><a asp-page="/Contact">Contact</a></li>
    </ul>
    <partial name="_LoginPartial" />
</div>

If the user is not signed in then _LoginPartial includes <a> tags that point to the login and register pages:

<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>

That all seems to make sense. But I would have expected the Areas folder structure to include the Register and Login folders. It does not. The only thing I find there is _ViewStart.cshtml

I know that the scaffolded code works. When I run the project, the Register link points to "/Identity/Account/Register", and the Login link points to "/Identity/Account/Login". Clicking on the Register link gets me a registration page that includes the text "Create a new account".

But I can't find the text "Create a new account" anywhere in the project.

Can someone tell me what I'm missing?

解决方案

It was announced during the preview of asp.net core 2.1 that the Identity UI would be moved to a new Razor Class Library. https://blogs.msdn.microsoft.com/webdev/2018/03/02/aspnetcore-2-1-identity-ui/

It is still possible to scaffold the Identity Views into your own project if you prefer local views: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio

这篇关于AspNet Core 脚手架应用程序中的登录和注册页面在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆