60

I'm running MVC3 and a windows auth web application. When I deploy to IIS6 it runs great until I hit a page that requires authentication. It then is auto-redirecting to /Account/Login when I have no trace of that in my application and my web.config is configured to windows auth.

Any ideas?

Here is my entire web.config file: http://pastie.org/1568510

tereško
  • 58,060
  • 25
  • 98
  • 150
Kevin Jensen
  • 1,418
  • 3
  • 18
  • 25

13 Answers13

155

Check whether you have WebMatrix.Data.dll and/or WebMatrix.WebData.dll deployed in the bin directory of your application. If they are there (and you know you don't use them) then try removing them and accessing a page that requires authentication.

Liam
  • 2,004
  • 2
  • 17
  • 18
  • 2
    This fixed it for me - I am using FormsAuthentication but my login page was Account/Logon instead of Account/Login. I believe this is the default when you create a new MVC3 application, and these WebMatrix.*.dll were added by VS2010 when I selected the Add Deployable Dependencies option. Slightly annoying when the default setup given to you by VS is faulty! – Duncan Watts Apr 27 '11 at 10:58
  • 18
    I've added this as a bug on Microsoft Connect, it wasted enough of my time! https://connect.microsoft.com/webmatrix/feedback/details/665150/including-webmatrix-data-dll-webmatrix-webdata-dll-overrides-forms-loginurl – Duncan Watts Apr 27 '11 at 11:14
  • 2
    The accepted answer did not work for me. This solution did fix it for me though. – Jesse Webb Jun 09 '11 at 17:07
  • Thanks. Like @Duncan-Watts, the WebMatrix.* assemblies got added to the _bin_deployableAssemblies folder, and hence, the bin folder. Note that I had to delete them from both folders, doing a Clean did not remove them from the bin folder as I had assumed. – Rick Glos Jun 29 '11 at 17:50
  • I did a bin deploy dependencies and the WebMatrix assemblies got loaded too! This broken everything as the question asker described. I had to manually remove the WebMatrix assemblies to get things working again. – 410 Jun 29 '11 at 19:57
  • 10
    Lost more than half a day to this 'bug' and while I am happy to have _finally_ found the answer, I'm still a bit steamed about it. *&@#^$!! – Jason Bunting Aug 01 '11 at 17:05
  • thanks! spent an hour on guessing wtf was wrong with one of two identical projects. the only difference was of course the webmatrix, added automaticly by vs's tools. someone should really do some testing @ microsoft – YavgenyP Oct 03 '12 at 09:24
  • I Wasted hours trying to figure this out and it took me that long to search the right combination of words to lead me here! Thanks! – Andrew Van Slaars Oct 30 '13 at 13:52
  • @liam, thank you for saving my sanity. How in the world did you figure it out? – triple.vee Jul 14 '20 at 17:17
29

In RTM try to add to <appSettings> in Web.config:

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

(Thx to Problem exclusively using Windows Authentication in ASP.NET MVC 3 Beta.)

Community
  • 1
  • 1
TN.
  • 18,874
  • 30
  • 99
  • 157
  • 2
    Just to note: this saves you also with the new MVC4... so 2 years later and the WebMatrix.* still have this problem. :( – Tallmaris Jun 14 '13 at 08:56
  • This worked perfectly. I was able to add it to the release config and not do weird things to the deployment process. Worth noting that my AccountController had the `[InitializeSimpleMembership]` tag. – emragins Mar 11 '14 at 19:46
  • Thanks a lot. All the answers on here have definitely helped out some *highly* irritated developers. – Nick Apr 06 '15 at 18:04
  • 1
    MVC5, still has this problem, and this solution helped me. I had to add WebMatrix during MVC4->MVC5 upgrade and so this problem has surfaced. – DenNukem Sep 11 '15 at 04:23
  • Ditto on the above comment. This took me like an hour to figure out. If you upgrade from MVC4 to MVC5 you cannot remove WebMatrix as indicated in the most upvoted accepted answer so adding the key in this answer worked for me. – John81 Sep 09 '16 at 13:47
  • Removing WebMatrix did not work (it just caused a new error for my application), but this fixed it for me! – blacksaibot Aug 29 '17 at 13:42
14

Not sure if you still have the issue or not, but try adding

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

to your web.config under appSettings. According to here and here, that should solve your problem.

Community
  • 1
  • 1
Dan Gardiner
  • 171
  • 1
  • 7
9

Try override WebMatrix.dll default for login url by adding this to your appSettings (web.config) :

<add key="loginUrl" value="~/Account/LogOn"/>

WebMatrix.dll set the login Url to /Account/Login, if this key isn't set in the config file... It works for me.

WebMad
  • 91
  • 1
  • 1
  • 1
    This is indeed the correct answer for MVC 4, as webmatrix is often needed for the default role provider so can't just be switched off or removed (as most answers suggest). This simply makes it use the correct controller/command for login. – iCollect.it Ltd Oct 09 '13 at 10:50
3

I had the same issue in my MVC4 project, only my project has Anonymous Authentication disabled outright, so Windows Authentication is always required.

I have no WebMatrix.* in my bin folder, and adding the autoFormsAuthentication and enableSimpleMembership keys to appSettings didn't do it for me.

Instead, I had to comment out the following:

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

And replace it with this:

<authentication mode="Windows" />

That did the trick.

Ber'Zophus
  • 7,497
  • 3
  • 22
  • 22
3

In RTM try to add to in Web.config:

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

The above post works. +1 Add this key before adding deployable dependencies.

2

I was using nopCommerce 2.65 and had this issue.

I did not have any of WebMatrix.Data.dll nor WebMatrix.WebData.dll deployed in the bin folder, but adding

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

in the web.config solved it.

TeamDotNet
  • 15
  • 2
1

Another way to override "login.aspx url redirection problem with MVC + IIS 7"... by adding this to your appSettings (web.config) :

<authentication mode="Forms">
<!--<forms loginUrl="~/Account/Login" timeout="2880" />-->
<forms loginUrl="~/Home" timeout="2880" />
</authentication>

...This resolved the problem for me

1

I fixed it this way
1) Go ot IIS
2) Select your Project
3) Click on "Authentication"
4) Click on "Anonymous Authentication" > Edit > select "Application pool identity" instead of "Specific User".
5) Done.

Akiv
  • 498
  • 4
  • 5
1

Make sure that all the authentication settings in IIS are correct.

For me the application that redirected to /Account/Login was running within a site that Anonymous authentication enabled. After disabling this in the site and enabling it for the application (together with Windows authentication) it was ok.

sourcx
  • 944
  • 7
  • 22
0

You can also go to the IIS on the server and go into Authentication modes and disable forms authentications.

This has me scratching my head in a demo. Embarassing.

0

I know this is a super old post. But I just ran across this after going through a tutorial on upgrading from MVC 4 to MVC 5. So I'm throwing it on just in case anyone else makes the mistake I did. My issue ended up being that I accidently added 'Microsoft.AspNet.WebPages.WebData' to my project while upgrading my references.

Running "Uninstall-Package Microsoft.AspNet.WebPages.WebData" restored my authentication to it's previous glory.

Caffeinius
  • 131
  • 4
0

In MVC for the 4.6 Framework this is done in 2 ways, the first is in the Web.Config as you would expect, the second one is done in the projectfile and is used to configure IIS Express:

<PropertyGroup>
..
    <IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
    <IISExpressWindowsAuthentication>disabled</IISExpressWindowsAuthentication>
</Property

Will disable Windows authentication and use anonymous when developing but is not used for the deploying the application.

Steef
  • 569
  • 5
  • 21