0

我的网站新闻部分有一个简单的路由。路由适用于几乎所有 URL 之类的

http://www.abc.com/Default.aspx

http://www.abc.com/Default.aspx?PageId=3

http://www.abc.com/Latest-News-Details.aspx?PageID=28&NewsID=39

仅当我尝试使用http://www.abc.com访问网站时才会出现问题,由于某种原因它将其重定向到自定义错误页面,我无法跟踪源错误并且我无法在我的本地主机上生成任何此类错误。

代码示例

全局.asx 文件

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    RegisterRoutes(RouteTable.Routes);
    //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}


public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
    routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
    routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
    routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
    routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));

    ////For News
    routes.MapPageRoute("NewsRoute", "{NewsID}/{PageID}/{NewsTitle}", "~/Latest-News-Details.aspx", false,
         new RouteValueDictionary {
                    { "NewsID", "0" },
                    { "PageID", "0"},
                    { "NewsTitle", "event-not-found" }},
         new RouteValueDictionary {   
                    { "NewsID", "[0-9]{1,8}" },
                    { "PageID", "[0-9]{1,8}" }
                }); 
}

现在我已经禁用了新闻部分的路由,如果我不注释上述路由代码,它仍然会产生错误。

我不确定是什么导致了问题。

我如何处理默认域的根目录,例如http://www.abc.com

我将不胜感激在这方面的帮助

4

1 回答 1

0

通过创建另一个路由来处理http://www.abc.com解决了问题

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
    routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
    routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
    routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
    routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));

    routes.MapPageRoute(
         "HomeRoute",
         "",
         "~/Default.aspx"
     );

    ////For News
    routes.MapPageRoute("NewsRoute", "{NewsID}/{PageID}/{NewsTitle}", "~/Latest-News-Details.aspx", false,
         new RouteValueDictionary {
                    { "NewsID", "0" },
                    { "PageID", "0"},
                    { "NewsTitle", "News-not-found" }},
         new RouteValueDictionary {   
                    { "NewsID", "[0-9]{1,8}" },
                    { "PageID", "[0-9]{1,8}" }
                }); 
}

对我来说很奇怪,因为相同的路由为其他网站工作,并创建了另一个回合来处理此类请求http://www.abc.com

于 2012-11-25T10:54:54.007 回答