简体   繁体   中英

Confusion around Forms and Windows Authentication in MVC

So I created an empty MVC project as a learning experience and now I've got some login stuff going, there's another problem...

It seems the thing likes to think I care about using Windows Authentication, so I added the following to my web.config file:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

Now, looking at the _LoginPartial.cshtml file:

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

I'm getting the following error now when I try to run the app:

Value cannot be null or empty.

This line is highlighted:

Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "Manage" })!

It occurred to me to just remove this, but it also seems to me that even with Forms Authentication, this would be useful, so I've got no idea what to do now.

Thanks in advance for any suggestions on implementing Forms Authentication here.

Use Individual User Accounts. I would recommend you start over rather than trying to modify authentication.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM