[英]Confusion around Forms and Windows Authentication in MVC
因此,我创建了一个空的MVC项目作为学习经验,现在我有了一些登录信息,还有另一个问题...
似乎是想让我关心使用Windows身份验证,所以我在web.config文件中添加了以下内容:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
现在,查看_LoginPartial.cshtml文件:
@if (Request.IsAuthenticated) {
<text>
Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "Manage" })!
@using (Html.BeginForm("Logoff", "Account", FormMethod.Post, new { id = "logoutForm" }))
{
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
}
</text>
} else {
<ul>
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
当我尝试运行应用程序时出现以下错误:
值不能为null或为空。
此行突出显示:
Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "Manage" })!
我想到只是删除它,但是在我看来,即使使用Forms Authentication,它也很有用,所以我不知道现在该怎么做。
在此先感谢您对实施表单身份验证的任何建议。
使用个人用户帐户。 我建议您从头开始,而不要尝试修改身份验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.