Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • set Anonymous Authentication: disabled
  • set Windows Authentication: enabled

Web.config

  • adding maxUrlLength="65536" attribute to the httpRuntime tag
  • adding maxQueryStringLength="10240" attribute to the httpRuntime tag
  • adding <authentication mode="Windows"/> within the <system.web> tag
  • adding the system.webServer tag (this ends up in a ERR_TOO_MANY_REDIRECTS whenever I add it):

    <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxUrl="10999" maxQueryString="2097151" />
          </requestFiltering>
        </security>
    </system.webServer>
    

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.

like image 975
smholvoet Avatar asked Jan 07 '23 17:01

smholvoet


1 Answers

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);
like image 162
smholvoet Avatar answered Jan 15 '23 13:01

smholvoet