Windows Authentication not working in ASP.NET MVC 5 web app

[亡魂溺海] 提交于 2019-12-04 10:40:42

问题


I have an ASP.NET MVC 5 app and am trying to enable Windows Authentication. The development machine is Windows Server 2008 R2, IIS Express 8.0, Visual Studio 2013 & .NET Framework 4.5.

I get a 404 Not Found error when ever I browse the app. The app enters a redirect loop with http://localhost:63455/Account/Login?ReturnUrl=%2F. Eventually the ReturnUrl ends up being very large as it gets appended to with each redirect.

My web.config looks like this:

  <system.web>
    <authentication mode="Windows"/>
  </system.web>

I've tried setting the Anonymous Authentication and Windows Authentication settings on the Development Server properties.

I've also tried adding the following appSettings:

<add key="autoFormsAuthentication" value="false"/>
<add key="enableSimpleMembership" value="false"/>

How can I get Windows Authentication working properly?


回答1:


The ConfigureAuth method in Startup.Auth.cs contained the following code which needed to be removed for Windows Authentication.

The code is used for Forms Authentication with OWIN.

        // Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login")
        });
        // Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);



回答2:


Just a heads up. You don't HAVE to remove cookie authentication entirely, although i did remove the externalsignincookie. Take a look at my project at https://github.com/vishnu4/AspNetMVC5WinAuth where I'm using OWIN and MVC5 to use windows authentication. Hopefully this helps anyone else trying to get it to work.



来源:https://stackoverflow.com/questions/23260283/windows-authentication-not-working-in-asp-net-mvc-5-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!