smholvoet
smholvoet

Reputation: 336

ASP.NET MVC Windows Authentication refusing to work

I've created a MVC Web Application using Visual Studio 2015. My goal is to change the authentication mode from none to Windows Authentication as I need so I can use the @User.Identity.Name method to identify the user. A short summary of what I've tried so far:

Project Properties

Web.config

Windows

  1. In Control Panel open "Programs and Features".
  2. Select "Turn Windows features on or off".
  3. Navigate to Internet Information Services > World Wide Web Services > Security and make sure the Windows authentication node is checked.

IIS Express

I tried creating a new project from scratch and neatly selecting Windows Authentication during the setup of the project. This works fine, so I believe my IISExpress settings are 100% correct. I even checked the applicationhost.config file and it doesn't have an entry for my specific project. Again, it works just fine if I select the correct authentication when creating a new project.


None of the above seems to work and all end up with an IIS error when I try to run the Visual Studio project:

HTTP Error 404.15 - Not Found
The request filtering module is configured to deny a request where the query string is too long.

This is what the URL looks like in the IIS Error Page:

http://localhost:52728/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252FLogin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252FAccount%2525252525252525252525252525252525252FLogin%2525252525252525252525252525252525253FReturnUrl%2525252525252525252525252525252525253D%252525252525252525252525252525252525252FAccount%252525252525252525252525252525252525252FLogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F

As you can tell I get an infinite redirect loop, and this is probably the reason why I'm unable to get this working. I do however have no idea what is causing it. Any help is greatly appreciated.

Upvotes: 4

Views: 2160

Answers (2)

smholvoet
smholvoet

Reputation: 336

Guess I'm able to answer my own question as I've just got it working. Might come in handy for people who experience similar errors in the future.

Solution: I had to comment out the following code in App_Start/Startup.Auth.cs:

 app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

Upvotes: 9

maciejgos
maciejgos

Reputation: 103

You could also check C:\Users[Your UserName]\Documents\IISExpress\Logs[Application Name] for any error details or URL used during request.

Upvotes: 1

Related Questions