ASP Net Identity代码被添加的来源未知,在构建/运行期间。

huangapple go评论60阅读模式
英文:

Unknown source of ASP Net Identity code being added during build/run

问题

我有一个asp net core解决方案,其中包含identity,我以为我已经删除了包含以下登录页面链接的代码部分:忘记密码注册新用户重新发送电子邮件确认使用其他服务登录(文本和链接)。但是这些内容仍然显示出来,我无法弄清楚为什么?

我已经在~\repo\Views\Shared\_LoginPartial.cshtml中的最后一行进行了'标记'。

代码:

@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager

<ul class="navbar-nav">
    @if (SignInManager.IsSignedIn(User))
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Kia Ora/Welcome @User.Identity.Name</a>
        </li>
        <li class="nav-item">
            <form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })">
                <button type="submit" class="nav-link btn btn-link text-dark">Logout</button>
            </form>
        </li>
    }
    else
    {

        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Login"></a>
        </li>
    }
    <!-- LoginPartial.cshtml file ends here-->
</ul>

当我使用localhost启动应用程序时,登录页面上仍然有所有链接,就好像我从未将它们删除过。这可以通过使用开发者工具查看页面(右键单击图像"在新标签中打开图像")来看到。

在父文件夹中有其他存储库文件夹,版本不同。但是我已经小心翼翼地在Visual Studio中打开了这个文件夹,并双击了解决方案文件。这个文件夹之外没有任何资源。这是怎么发生的?

我相信bootstrap容器代码和HTML角色属性并没有提供任何线索。我可能是错的。

ASP Net Identity代码被添加的来源未知,在构建/运行期间。

英文:

I have an asp net core solution with identity which I thought I had removed the section of code that included these login page links: Forgot Password, Register as a New User, Resend Email Confirmation and Use Another Service to Login (text & link) But this content is displayed and I can't figure out why?

I have 'marked' the last line of ~\repo\Views\Shared\_LoginPartial.cshtml

The code:

@using Microsoft.AspNetCore.Identity
@inject SignInManager&lt;IdentityUser&gt; SignInManager
@inject UserManager&lt;IdentityUser&gt; UserManager

&lt;ul class=&quot;navbar-nav&quot;&gt;
    @if (SignInManager.IsSignedIn(User))
    {
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;Identity&quot; asp-page=&quot;/Account/Manage/Index&quot; title=&quot;Manage&quot;&gt;Kia Ora/Welcome @User.Identity.Name&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;form class=&quot;form-inline&quot; asp-area=&quot;Identity&quot; asp-page=&quot;/Account/Logout&quot; asp-route-returnUrl=&quot;@Url.Action(&quot;Index&quot;, &quot;Home&quot;, new { area = &quot;&quot; })&quot;&gt;
                &lt;button type=&quot;submit&quot; class=&quot;nav-link btn btn-link text-dark&quot;&gt;Logout&lt;/button&gt;
            &lt;/form&gt;
        &lt;/li&gt;
    }
    else
    {

        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;Identity&quot; asp-page=&quot;/Account/Login&quot;&gt;&lt;/a&gt;
        &lt;/li&gt;
    }
    &lt;!-- LoginPartial.cshtml file ends here--&gt;
&lt;/ul&gt;

When I launch the app using localhost, the login page has all the links, as though I never removed them. This can be seen looking at the page using Developer Tools (right-click image "Open image in new tab"

There are other repo folders, in the parent folder, with different versions. But I have been careful to open this folder in Visual Studio and double click on solutions file. There are no resources outside of this folder. How can this happen?

I believe the bootstrap container code and the HTML role attribute don't give any clues. I could be wrong.

ASP Net Identity代码被添加的来源未知,在构建/运行期间。

答案1

得分: 2

以下是翻译好的部分:

"I think you are getting a bit cross-eyed looking for things, that are magically there, if you don't know where to look."

"我觉得你正在苦苦寻找那些神奇地存在的东西,如果你不知道在哪里找的话,可能会让你眼花缭乱。"

"The code you are showing us is the LoginPartial view, that is injected into your Navbar. If you haven't changed it, that should be in _Layout.cshtml:

"你展示给我们的代码是LoginPartial视图,它被注入到你的导航栏中。如果你没有修改它,它应该在_Layout.cshtml中:"

    &lt;ul class=&quot;navbar-nav flex-grow-1&quot;&gt;
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;&quot; asp-page=&quot;/Index&quot;&gt;Home&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;&quot; asp-page=&quot;/Privacy&quot;&gt;Privacy&lt;/a&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;partial name=&quot;_LoginPartial&quot;/&gt;
&lt;/div&gt;

"你展示给我们的代码是LoginPartial视图,它被注入到你的导航栏中。如果你没有修改它,它应该在_Layout.cshtml中:"

"What you are showing us as a screenshot is the Login view, which ... is not there. Asp.net core automatically adds them behind the scenes as a default implementation. You can of course override them."

"你所展示的截图是登录视图,然而实际上...并不存在。ASP.NET Core会在后台自动添加它们作为默认实现。当然,你可以进行覆盖修改。"

  • Right click your project
  • Click on "Add New Scaffolded Item"
  • Click "Add Identity"
  • Select the Login View (and any other you want to modify)

"右键单击你的项目

  • 点击“添加新的脚手架项”
  • 选择“添加身份”
  • 选择登录视图(以及其他你想要修改的内容)"

Once the process has finished, those scaffolded items should be inside your /Areas/Identity folder.

"一旦过程完成,这些脚手架项目应该位于你的/Areas/Identity文件夹中。"

Reference: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-7.0&amp;tabs=visual-studio

"参考链接:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-7.0&tabs=visual-studio"

英文:

I think you are getting a bit cross-eyed looking for things, that are magically there, if you don't know where to look.

The code you are showing us is the LoginPartial view, that is injected into your Navbar. If you haven't changed it, that should be in _Layout.cshtml:

&lt;div class=&quot;navbar-collapse collapse d-sm-inline-flex justify-content-between&quot;&gt;
    &lt;ul class=&quot;navbar-nav flex-grow-1&quot;&gt;
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;&quot; asp-page=&quot;/Index&quot;&gt;Home&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class=&quot;nav-item&quot;&gt;
            &lt;a class=&quot;nav-link text-dark&quot; asp-area=&quot;&quot; asp-page=&quot;/Privacy&quot;&gt;Privacy&lt;/a&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;partial name=&quot;_LoginPartial&quot;/&gt;
&lt;/div&gt;

What you are showing us as a screenshot is the Login view, which ... is not there. Asp.net core automatically adds them behind the scenes as a default implementation. You can of course override them.

  • Right click your project
  • Click on "Add New Scaffolded Item"
  • Click "Add Identity"
  • Select the Login View (and any other you want to modify)

Once the process has finished, those scaffolded items should be inside your /Areas/Identity folder.

Reference: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-7.0&amp;tabs=visual-studio

答案2

得分: 0

问题中陈述了一种假设,即 Microsoft Web App 默认的注册详细信息等已经从解决方案中删除。这正是我所需要的,而且证明是正确的。我最初使用的方法是,认为这是最好的,就是脚手架化所有身份元素(在脚手架的“添加身份”页面上所有方框都被勾选),然后编辑/删除我不需要的部分。我唯一需要做的编辑就是从~\Areas\Identity\Pages\Account\Login.cshtml文件中删除问题中的项目。

我相信上述文件通过文件~\Views\Shared\_LoginPartial.cshtml链接,以提供一个“干净”的登录页面(没有注册详细信息)。这可以在问题的代码部分看到。

问题是:

  • 文件夹~\Areas\Identity\Pages\Account曾被暂时排除在项目之外。
  • 我不明白“默认代码”是从哪里来的,重新将注册详细信息添加到登录页面上。

我仍然不明白如何将 Account 和 Management 文件夹中的所有文件排除在项目之外,从而得到默认的登录页面。手动检查所有我的代码文件似乎表明这是不可能的。

对于寻找有关脚手架化身份信息的信息的任何人,我找到了以下有用的资源。

ASP.NET Core 中的身份介绍

在AspNet Core脚手架应用程序中,登录和注册页面在哪里?

英文:

The question stated a presumption that Microsoft Web App default registration details etc had been removed from the solution. This is what I required and this proved to be correct. The original method I used, believing to be the best, was to scaffold all identity elements (all boxes ticked on Add Identity page of scaffolding) and then edit/remove what I didn't need. The only editing I needed to do was to remove the items in the question from ~\Areas\Identity\Pages\Account\Login.cshtml

I believe the above file is linked via the file ~\Views\Shared\_LoginPartial.cshtml to provide a 'clean' login page (without registration details) This can be seen in the code section of the question.

The issues were:

  • the folder ~\Areas\Identity\Pages\Account had been temporarily excluded from the project.
  • I didn't understand where the 'default code' had come from which reintroduced the registration details back onto the login page.

I still don't understand how all the files in Account & Management folders can be excluded from the project resulting in the default login page. A manual check of all my code files would suggest this is not possible.

For anyone looking for information on scaffolding identity. I found the following useful.

Introduction to Identity on ASP.NET Core

Where are the Login and Register pages in an AspNet Core scaffolded app?

huangapple
  • 本文由 发表于 2023年3月7日 14:22:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658600.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定