I ran into a problem the other day that I could find very little information about, so I thought I’d put a blog post together to:
- remind me
- hopefully help anybody else who runs into this problem
I picked the obtuse title as it is very close to the ambiguous error message I got and should hopefully help other people find the solution far faster than I did.
Recently, I was working on an MVC3 application. It was working well and I wanted to sort out dependencies for our CI server so that we didn’t need to have MVC installed on the server for the code to build and intended to do this by adding bin deployable dependencies.
I made a couple of small changes to views, a controller change to home and then clicked “Add Deployable Dependencies…” and when the dialog appeared, I selected ASP.NET MVC.
I then did a quick sanity check of build, run tests and run up the application before checking in only to find that when I ran the site up I got a yellow screen of death:
WTF! The unit tests had all passed and I had been testing the views themselves a moment or two ago by logging in and using the site. Unfortunately, I hadn’t just made a single change since I last checked in (my bad) so I went back and checked all my changes one at a time to ensure that none of my changes could be causing the problem and found nothing.
I then took a closer look at the error and saw that the URL it was trying to request was /Account/Login which was incorrect as the name of the view that handled logging in was called Logon. I checked the web.config and then found the default values hadn’t been changed:
I then tried changing Account to something as abstract as ABCDEF but got a similar error only instead of the requested URL being /Account/Login it was now /ABCDEF/Login. Something was incorrectly getting involved when redirecting to the loginUrl and altering the route to replace Logon with Login.
I then turned to Google and found… nothing, well nothing that seemed to apply to me that is.
This only left me with the unthinkable, could it be something to do with the deployable dependencies? I took a closer look at the assemblies that had been added and saw System.Web.Helpers.dll in the bin deployable folder which I know is linked with Web Matrix. I then did a bit of exploration with Reflector turned up no particular dependency on this assembly to any of the other bin deployable dependencies or any of my referenced assemblies and so I removed it and the site started working again!
A bit more focused Googling then turned up that the behaviour I was seeing was linked to SimpleMembership in WebMatrix, I also noticed that if you look at System.Web.Configuration
and the FormsAuthentication
class, you will find that the property LoginUrl
has a default value of login.aspx. I haven’t specifically tracked it back to this, but it is suspicious and would certainly fit the behaviour I was seeing.
In my second Google attempt, I had also found that if you don’t want to remove the assembly, you can add <add key="enableSimpleMembership" value="false" />
to the AppSettings
of your web config and this will also allow the site to work, but why do you have to add this at all?
From forum posts and some blog posts, I found it appears that you would perhaps use System.Web.Helpers
in MVC if you wanted to use one of the helpers that you find in WebMatrix such as the Twitter helper and that the SimpleMembership provider was being called by default rather than the normal authentication mechanism in MVC resulting in the behaviour I was seeing.
IMHO when you add the bin deployable files in VS that includes System.Web.Helpers
, it should either:
- add the missing web.config
AppSetting
for you
- not add the assembly if it's not needed
- add the functionality without the need for the setting
Hopefully, this post may help somebody else who stumbles into this issue and save them the time it took me to work out why my working code suddenly became broken.