Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

ASP.NET MVC Area not picking up the correct route

I am in the process of debugging a routing issue on my MVC 3 application and I am using Phil Hacks routing debugger.

I cannot seem to work out where the route highlighted in yellow below is originating. Each time I run my application with the following request

http://www.mywebsite.com/auth/login?ReturnUrl=/

this route comes first and then gives me a 404 error as I do not have an index action. As you can see I have set my default routes to use the Login action method but still this route persists.

enter image description here

I have the following route configurations:

AuthAreaRegistration

public class AuthAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Auth";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "login",
            "auth/login/{*returnPath}",
            new { controller = "Auth", action = "LogIn", id = UrlParameter.Optional }
        );

        context.MapRoute(
            "Auth_default",
            "Auth/{controller}/{action}/{id}",
            new { controller = "Auth", action = "LogIn", id = "" }
        );
    }
}

Global.asax (Using T4 MVC Templates)

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Home",
            "{controller}/{action}/{id}",
            MVC.Home.Index(), new { id = UrlParameter.Optional },
            new string[] { "MyNamespace.WebUI.Controllers" }

        );

        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            MVC.Home.Index(), new { id = UrlParameter.Optional },
            new string[] { "MyNamespace.WebUI.Controllers" }
        );
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don’t like to answer my own question but after a day of trying to solve this problem I thought I would post the answer in case anyone else has the same issue.

It turns out that my application was holding onto old routes and populating them into my route collection. I deleted all the files in my bin folder and rebuilt my solution and everything worked as it should.

I have answered this question in a little more detail here:

Does ASP.NET MVC create default routes for areas


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...