find a location for property in a new city

Tuesday, 14 June 2011

Two bugs in ASP.NET MVC 3 and a workaround for both

So I spent an hour today arsing about with a couple of ASP.NET MVC 3 bugs. One was a Routing issue that caused it to act differently to MVC 2. The second I found was a FormsAuthentication issue that insisting on sending me to /Account/Login.

Amazing how this crept in really given that it was community tested to death with such a massive ASP.NET MVC following so it is a wonder they weren't weeded out and fixed before RTM. Oh well, don't pretend you don't like a challenge.

Routing doesn't work the same in MVC3 from MVC2

Here is an example of this bug in action

My current route is:
routes.MapRoute("groups", "groups/{groupSlug}/{action}/{id}/{urlTitle}",
                    controller = "groups",
                    groupSlug = UrlParameter.Optional,
                    action = "index",
                    id = UrlParameter.Optional,
                    urlTitle = UrlParameter.Optional

I am using this route in an ActionLink like this (well obviously I've changed it for clarity - but I was totally using T4MVC!):
<%: Html.ActionLink(item.Group.Title, "index", new { groupSlug = "something" })%>

In MVC2 it that produces the URL /groups/something. But in MVC3 it produces the URL /groups?groupSlug=something.

MVC3 Routing UrlParameter.Optional workaround

I struggled with this for a good few hours, many a time exclaiming that, "my route IS there! What the hell is wrong with you?!" I took it apart piece by piece to discover that MVC3 no longer likes multiple UrlParameter.Optional's in a row.

A rather ugly workaround for this is to put in a new route for each of these problem routes that have no reference to the following UrlParameter.Optional's. So AFTER the above route you I need to put in another route like this:
//workaround for MVC3 bug
routes.MapRoute("groupsFix", "groups/{groupSlug}/{action}",
                    controller = "groups",
                    groupSlug = UrlParameter.Optional,
                    action = "index"

Since writing this I have discovered it is a known issue and Phil Haack has a much better explanation than me! Obviously.

FormsAuthentication.LoginUrl is always /Account/Login

I have setup my forms authentication in web.config to register the LoginUrl as "~/login" but since upgrading to MVC3 it has decided to ignore that and now FormsAuthentication.LoginUrl returns "~/Account/LogIn" regardless of what I set in web.config.

There is a workaround for this though. You simply need to add this line to your AppSettings:

and everything works how it used to. Strangeness indeed.


Live with it. Fix up your errors as explained above and continue staying up to speed with ASP.NET MVC. It's worth it if even just for Razor alone.

Follow britishdev on Twitter


  1. What is the solution for FormsAuthentication.LoginUrl is always /Account/Login ??? I can´t see anything after AppSettings:

  2. That's strange. What browser are you using? The line you can't see is using JavaScript to syntax Higlight it so maybe that is causing problems.

    Anyway the line is: <add key="loginUrl" value="~/login"></add>

  3. This comment has been removed by the author.

  4. Cool, I'd these problem other day and I've solved with this post. Thanks.

  5. I have the same problem when migrating from MVC 5 to MVC 6.

    ASP.NET MVC Training | Dot Net Training in Chennai

  6. Really interesting content which is unique which provided me the required information.
    Dot Net Training in Chennai | .Net training in Chennai | FITA Training | FITA Velachery .

  7. Awesome Post! I like writing style, how you describing the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.
    FITA Chennai complaints|Python Training in Chennai|SAS Training in Chennai

  8. This is really a great post. Thank you for taking time to provide us some of the useful and exclusive information with us. Keep on blogging!!

    SAS Training in Chennai

  9. This is an incredible rousing article.I am essentially satisfied with your great work.You put truly supportive data.Visit for more info Buzz Apps

  10. This is the best application on the drop today. There access to enjoy great moments of relaxation: age of war 2|
    age of war 5
    Great! Thanks for sharing the information.Summon creatures to fight enemy units and demolish the opposing castle. Your castle is equipped with a crossbow, which you can use to shoot enemies age of war 6. Make sure you upgrade skills to increase your chances of winning battles.
    The goal of Age of War is to survive longer than the computer and to outlast him you’ll need to train the right troops while balancing your offence and defence in this high paced, quick thinking flash game age of war 4
    . Train troops of you own to combat the computers. As you kill off the computer troops, you will gain EXP and you will eventually advance to the next age.
    Choose a starter deck and prepare for an epic war!age of war 3

    Command your units in each battle to attack the enemy’s castle, while protecting your own base earn to die 2. Earn and upgrade cards to help you conquer the land.age of war

    happy wheels | tank trouble
    Thanks for the best was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    cubefield It contains a plethora of tools and objects for level building such as harpoon guns,blocks and vans. Users can upload their maps to a public server where they are accessible

  11. Great! Thanks for sharing the information. That is very helpful for increasing my knowledge in this fiel
    Red Ball | | duck life | Slitherio
    Red Ball 2 | Red Ball 3 | Red Ball 4

  12. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

  13. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    SAS Training in Chennai | SAS Course in Chennai

  14. This is really great work. Thank you for sharing such a useful information here in the blog.
    Harvard case solution

  15. I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs.
    Mechanical Engineering Homework Help

  16. This was a great and interesting article to read. I have really enjoyed all of this very cool information.
    Project Management online Assistance


  17. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

  18. Searching for an assignment helper that assists you in writing academic writing. Visit our site and get ready to get your assignment written by well-qualilfied assignment writers. Assignment Help

  19. Even when things have been community tested to death with such a massive ASP.NET MVC following, stuff is bound to crop up now and again

    Digital Signage Software
    Digital Signage Software trends

  20. Thank you for this valuable information. The information you shared is very interesting. Get your business to the next level in simple steps. We provides lowest price of erp software Software for our clients.
    erp software in chennai | erp providers in chennai | online events registration

  21. by visiting this site I found cool stuff here Term Paper Writing Service keep it up.

  22. Struggle to attempt the academic assignments is real for the students. However, there is a solution to every problem. You could find the solution for your coursework with our assignment writing service and can get a well-written Assignment Help from us.

  23. That information is you share with us such a interesting knowledgeable. We help Students to complete in there essay writing work from our expert academic writers. Our Essay Writing Service 24*7 available for students at reasonable price.

  24. This information is good and this is knowledgeable information. Singapore hires renting work experts because they provide excellent Assignment Help Singapore service with quality assignments at low prices.

  25. Make My Assignments|Assignment help make customized assignments. Our team of experts is ready to make your assignments 24x7. We provide 100% Plagiarism free work
    Best Marketing assignment help service at affordable prices that too plagiarism free
    I really liked the article and i am really fond of such kind of people who writes such good content. Keep it up
    [url=""]Marketing assignment Help[/url]
    [url=""]assignment making service[/url]
    [url=""]UOP Assignment help[/url]

  26. I am big fan of such lovely little things that smell so good. I have numerous aromatic candles at home! It helps me to relax after my working days. Looking for a Wedding Photographer?

  27. The information you shared is really interesting. I appreciate the fact that you have tried and took time to post here. homework help

  28. Visit our website to know the reviews of different assignment writing service providers.
    Visit allassignmenthelp reviews

  29. What a great blog, thanks for sharing! Wonderful Photos and such a interesting things...Send Gifts To pakistan