Asp.Net Mvc RouteData填充了错误的参数

时间:2009-06-15 07:57:17

标签: asp.net-mvc routing

routes .Add ("Detail",
                new Route ("{maincategory}/{category}",
                          new RouteValueDictionary (new { controller = "Category", action = "Detail"}),
                          new RouteValueDictionary (new { category = new FromValuesListConstraint ("")}),
                          new MyRouteHandler ()));

        routes.Add("Category",
                new Route("{category}",
                          new RouteValueDictionary(new { controller = "Category", action = "Index", category = "" }),
                          new RouteValueDictionary(new { category = new FromValuesListConstraint("") }),
                          new MyRouteHandler()));

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults

        );

我的路线是这样的。但是当我运行网站主页时会显示。显示主页后会发生一些事情并再次发出一个新的任务(我不知道为什么)我覆盖MvcRouteHandler并在其中放置一个断点。

public class MyRouteHandler : MvcRouteHandler
{
    protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var url = HttpContext.Current.Request.RawUrl;
        var route = requestContext.RouteData;  
        return new MvcHandler(requestContext);
    }
}

url变量是/Content/Divider.gif。因为显示主页后,应用程序出错。我尝试了一切,以新手mvc用户的身份理解这个问题。但我找不到任何东西。

谢谢!

1 个答案:

答案 0 :(得分:1)

您的网站上是否存在文件/Content/Divider.gif?

它可能正在尝试将其作为路由执行,因为该文件不存在而且这是您问题的根源。