New Asp.Net MVC5 project produces an infinite loop to login page

后端 未结 21 3175
粉色の甜心
粉色の甜心 2020-11-29 20:12

I am creating a brand new projet with Visual Studio 2013, I choose Asp.Net MVC and the framework 4.5.1 The project is created, then, I do nothing else than F5 to start the d

相关标签:
21条回答
  • 2020-11-29 20:53

    Please be aware that this is potentially harmful advice, it's rarely a good idea to modify an applicationhost config file directly, there are usually tools that will do this for you, safely (for example, from within Visual Studio.) Before proceeding, be sure to create a backup copy of this file in the event your IIS Express becomes trashed.

    To fix this problem, I took the default IIS configuration file located here :

    C:\Windows\System32\inetsrv\config\applicationHost.config
    

    To my document

    %userprofile%\documents\iisexpress\config\applicationhost.config
    

    And it worked.

    This was because I had some Windows Authentification set and not the anonymous account.

    0 讨论(0)
  • 2020-11-29 20:54

    ASP.Net MVC 5 template adds Microsoft.Owin and related libraries to the project. Since Owin infrastructure doesn't require Forms Authentication, the template also introduces the following key in web.config.

    <system.webServer>
      <modules>
        <remove name="FormsAuthentication" />
      </modules>
    </system.webServer>
    

    Presence of this key could be a reason for undesirable looping back to Login page. Commenting it may help fix the problem for some people.

    0 讨论(0)
  • 2020-11-29 20:55

    I had the same issue with my Asp.Net MVC 4 project. I resolved it by going to Startup.cs and commenting out the line for ConfigureAuth(app)

        public void Configuration(IAppBuilder app)
        {
            //ConfigureAuth(app);
        }
    

    I also made sure that I had Windows Authentication enabled in IIS for my project, and all other authentication options disabled.

    0 讨论(0)
  • 2020-11-29 20:56

    I solved the same problem thanks to this accepted answer: ASP.NET Login Redirect Loop when user not in role.

    It is possible that the controller containing Login action is decorated with an AuthorizeAttribute (even a custom one) while the login action is not decorated with AllowAnonymous attribute. Removing AuthorizeAttribute from the controller and adding AllowAnonymous to login action may be a possible solution.

    0 讨论(0)
  • 2020-11-29 20:57

    in my case it was a very wired problem , i decorated the home controller by non existent role. so it causes a redirection loop.

    0 讨论(0)
  • 2020-11-29 20:57

    Go to to your applicationhost.config file and set anonymousauthentication = "true"

    <authentication>
    
                <anonymousAuthentication enabled="true" userName="" />
                <windowsAuthentication enabled="true">
                    <providers>
                        <add value="Negotiate" />
                        <add value="NTLM" />
                    </providers>
                </windowsAuthentication>
    
            </authentication>
    
    0 讨论(0)
提交回复
热议问题