ASP.NET MVC地区没有拿起正确的路由 [英] ASP.NET MVC Area not picking up the correct route

查看:227
本文介绍了ASP.NET MVC地区没有拿起正确的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的MVC 3应用程序的调试路由问题的过程中,我用菲尔黑客路由调试器。

我似乎无法制定出该路由以黄色突出显示如下始发。每次我跑我的下面的请求的应用程序

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

这条路线是第一位的,然后给了我一个404错误,因为我没有一个index动作。正如你可以看到我已经为我设置的缺省路由使用的登录操作方法,但仍这条路线仍然存在。

我有以下的路由配置:

AuthAreaRegistration

 公共类AuthAreaRegistration:AreaRegistration
{
    公众覆盖字符串AREANAME
    {
        得到
        {
            返回验证;
        }
    }    公共覆盖无效RegisterArea(AreaRegistrationContext上下文)
    {
        context.MapRoute(
            登录,
            认证/登录/ {*} ReturnPath这样,
            新{控制器=验证,行动=登录,ID = UrlParameter.Optional}
        );        context.MapRoute(
            Auth_default
            认证/ {控制器} / {行动} / {ID}
            新{控制器=验证,行动=登录,ID =}
        );
    }
}

Global.asax中(使用T4模板MVC)

 公共静态无效的RegisterRoutes(RouteCollection路线)
    {
        routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);        routes.MapRoute(
            家,
            {控制器} / {行动} / {ID}
            MVC.Home.Index(),新的{ID = UrlParameter.Optional},
            新的String [] {MyNamespace.WebUI.Controllers}        );        routes.MapRoute(
            默认,
            {控制器} / {行动} / {ID}
            MVC.Home.Index(),新的{ID = UrlParameter.Optional},
            新的String [] {MyNamespace.WebUI.Controllers}
        );
    }


解决方案

我不喜欢回答我的问题,而是试图解决这个问题的前一天,我想我会发布的情况下,任何人有答案同样的问题。

事实证明,我的申请被持有到老路线,并将其填充到我的路由集合。我删除所有文件在我的bin文件夹并重建我的解决方案和一切工作,因为它应该。

我在这里稍微详细回答了这个问题:

<一个href=\"http://stackoverflow.com/questions/4861702/does-asp-net-mvc-create-default-routes-for-areas\">Does ASP.NET MVC创建领域默认路由

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.

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" }
        );
    }

解决方案

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

这篇关于ASP.NET MVC地区没有拿起正确的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆