2012-11-25 87 views
0

我爲我的網站新聞部分有一個簡單的路由。路由工作正常,幾乎所有的URL像ASP.net 4.0路由不能與主要域名一起工作

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訪問網站的一些情況原因它重定向到自定義錯誤頁面,我不能跟蹤錯誤來源&我不能在我的本地主機上產生任何這樣的錯誤。

代碼示例

global.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

默認域我希望幫助這對於

+0

你hav在IIS中設置默認文檔? – pkmiec

+0

它工作,如果路由被禁用,我認爲問題是與路徑 – Learning

回答

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