开发者

Using Windows auth, but getting redirected to forms auth login page?

We're running IIS7 and have windows authentication enabled. Everything else is disabled. When we go to the page though, we aren't prompted for a windows logon, but are redirected to the default forms authentication login page (Account/Login?ReturnUrl=%2f).

Any ideas? Thanks开发者_StackOverflow.


As well as this:

<authentication mode="Windows"></authentication>
<authorization>
  <allow users="*"/>
</authorization>

You also might need these two appSettings too:

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

See this answer on SO and Known Issues from the MVC3 release notes.


In case anyone gets this far and the other answers have not remedied the problem yet, check for a file named Startup.Auth.cs in the App_Code folder of your project. In my situation, the block of code below was active and causing the redirect to a login page I did not want to use.

    // Enable the application to use a cookie to store information for the signed in user
    // and also store information about a user logging in with a third party login provider.
    // This is required if your application allows users to login
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);


Have you made sure that Windows authentication is enabled in your asp.net application and not forms?

Make sure you web.config file is setup with:

<authentication mode="Windows"/>
<authorization>
    <allow users="*"/>
</authorization>

You probably have the authentication mode in your application still set to forms authentication and that is why the forms functionality is kicking in.

Also don't forget to adjust any nest web.config files as well if you have nested folders in your application.


Actually this SO Question solved it for me - I haven't tried the above solution though:

ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login

It is simply to check whether your bin directory contains any of: WebMatrix.Data.dll and/or WebMatrix.WebData.dll, and if yes - Remove Them!

Then make sure they never publish again into the bin by removing them from your project's references list..


@panhandel's solution above should be the accepted answer. It lead me into the right direction. BTW it was the App_Start folder in my case, not App_Code. Even by removing references and excluding code files, it didn't resolve my issue. I had to delete and recreate the whole solution. But this time I was careful enough not to leave the default selection of "Individual User Accounts" under the Authentication section since I was using Windows authentication.

Using Windows auth, but getting redirected to forms auth login page?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜