MVC5 Redirects to Login.aspx when using Windows Authentication

后端 未结 4 2505
抹茶落季
抹茶落季 2020-12-15 04:16

After upgrading from MVC 4 to MVC 5, my application (when started from within Visual Studio) gives the following error. It might also be worth noting that I am hosting both

相关标签:
4条回答
  • 2020-12-15 04:25

    If you are running your app locally and getting an http 401 error then you may need to change your IISExpress configuration. Go to Documents>IISExpress>applicationhost.config

    Make sure windowsAuthentication is enabled:

                 <windowsAuthentication enabled="true">
                    <providers>
                        <add value="Negotiate" />
                        <add value="NTLM" />
                    </providers>
                </windowsAuthentication>
    
    0 讨论(0)
  • 2020-12-15 04:27

    In addition to the above answers, depending on which template was used to create the project you may have Startup.Auth.cs in the App_Start folder with the following code which can be commented out:

    // 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);
    
    0 讨论(0)
  • 2020-12-15 04:38

    I was able to resolve the issue by adding the following to the appSettings section as per the response to this question.

    <add key="autoFormsAuthentication" value="false" />
    <add key="enableSimpleMembership" value="false"/>
    
    0 讨论(0)
  • 2020-12-15 04:43

    In addition, Web.Config System.web section should NOT contain this line:

    <authentication mode="Forms" />
    

    And in my case it worked.

    0 讨论(0)
提交回复
热议问题