27

I'm creating an Intranet site in ASP.NET MVC 3 Beta and would like to use Windows Authentication exclusively. In addition, I'd like to use the Visual Studio Development Server in VS2010.

I modified the default web.config file to remove all references to forms authentication and switched to this:

<authentication mode="Windows"  />
<authorization>
  <deny users="?" />
</authorization>

However, when I launch my site and get the default page, I get this reply:

HTTP/1.1 302 Found
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 02 Nov 2010 14:05:19 GMT
X-AspNet-Version: 4.0.30319
Location: /Account/Login?ReturnUrl=%2f
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 145
Connection: Close

Which leads to this message in my browser:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Account/Login

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 Version:4.0.30319.1

If I select the "NTLM Authentication" in the project properties under "Use Visual Studio Development Server" then I correctly get this reply on connect:

HTTP/1.1 401 Unauthorized Server
ASP.NET Development Server/10.0.0.0
Date: Tue, 02 Nov 2010 14:07:37 GMT
Content-Length: 1211 
WWW-Authenticate: NTLM

But then when I authenticate, I get the 302

I think this is just a matter of clearing out some default value but am not sure ("/Account/Login" doesn't appear anywhere in my web.config files). If I remove the "deny" part then things work fine except that I don't get an authenticated Principal and effectively remain anonymous.

I believe this used to work in ASP.NET MVC 2 and VS2008 by just changing the authentication mode to Windows, however it doesn't seem to work that way any more.

I know I'm probably missing something basic. Thanks!

Note: This question is similar to the "Problem restricting anonymous access to an ASP.Net MVC Site" question, but different in that I want to exclusively use Windows authentication.

1
  • 7
    In MVC3 RTM, this seems to help <add key="enableSimpleMembership" value="false"/> source Jul 1, 2011 at 7:12

3 Answers 3

38

I had exactly the same problem. Turns out there was a change in MVC 3 (fairly well hidden, too) that has Forms authentication automatically enabled by default, in order to disable it add the following line to your root Web.config file, under the appSettings key...

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

Hope that helps!

5
  • Thank you! I hadn't heard of this "feature" before. Disabling it fixed it and it runs great now. Thanks again!
    – Jeff Moser
    Nov 2, 2010 at 15:54
  • 1
    No problem - took me a day to track that one down!
    – Kieron
    Nov 2, 2010 at 15:56
  • 2
    Phil Haack (@haacked) informed me that this issue is in the release notes and will be fixed: asp.net/learn/whitepapers/mvc3-release-notes
    – Jeff Moser
    Nov 2, 2010 at 17:59
  • 8
    As per the document Jeff commented - I had to also add this key to get this working - <add key="enableSimpleMembership" value="false" /> Sep 23, 2011 at 14:59
  • Note for Visual Studio/IIS/IIS Express Users: the web server must also be configured for windows authentication. It doesn't only depend on the web.config file.
    – JB.
    Dec 19, 2012 at 13:50
15

FYI, in case this helps others : In my case, I only had to add <add key="enableSimpleMembership" value="false"> to fix the issue and <add key="autoFormsAuthentication" value="false" /> was not required. I also found this blog post very useful as an explanation http://www.codeproject.com/Articles/292149/The-resource-cannot-be-found-Account-Login?msg=4092212#xx4092212xx

Any thoughts on potential ramifications/side-effects of this fix?

also I am disappointed this issue has not yet been fixed by ms after a year +.

thanks.

4
  • 2
    I am disappointed as well. And as you mentioned, I only needed to add <add key="enableSimpleMembership" value="false">. +1 for providing the link :)
    – user631063
    Jan 10, 2012 at 19:35
  • the key aspect from this article relates to deployable dependencies!!
    – Ahmad
    Aug 14, 2012 at 7:24
  • Thanks for this! this seems to have fixed for me too!
    – Lazy Dave
    Mar 22, 2013 at 12:05
  • And this was it for me too! thanks so much The issue occurred when creating the default MVC4 project within VS2012 Update 4. My guess is that this will have to do with the newer templates included in the latest versions of 2012.
    – JSancho
    Apr 8, 2014 at 14:06
1

Check if you have a WebMatrix.Data.dll at your bin. http://blog.fujiy.net/post/aspnet-mvc-windows-authentication-redirecionando-pro-login, http://blogs.catapultsystems.com/rhutton/archive/2012/07/20/mvc3-with-windows-authentication-redirected-to-accountlogin.aspx

1
  • The <add key="enableSimpleMembership" value="false" /> key did nothing for me, but removing all WebMatrix*.dll files worked like a charm! Thanks!!!
    – David
    Jul 15, 2013 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.