2013-03-12 106 views
1

嗨,朋友誰能解決這個問題我真的越來越堅果我也閱讀文章和教程,並根據我已經做了編碼了。錯誤即時得到是在asp.net 4.0網址重寫

A route named 'xxxxx' ould not be found in the route collection. 
Parameter name: name 

全球ASAX

<%@ Application Language="C#" %> 
<%@ Import Namespace="System.Web.Routing" %> 

<script runat="server"> 

    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.MapPageRoute("test2-testurl", "test2/{category}", "~/test2.aspx"); 
    } 
    void Application_Start(object sender, EventArgs e) 
    { 
     RegisterRoutes(RouteTable.Routes); 
     // Code that runs on application startup 

    } 

    void Application_End(object sender, EventArgs e) 
    { 
     // Code that runs on application shutdown 

    } 

    void Application_Error(object sender, EventArgs e) 
    { 
     // Code that runs when an unhandled error occurs 

    } 

    void Session_Start(object sender, EventArgs e) 
    { 
     // Code that runs when a new session is started 

    } 

    void Session_End(object sender, EventArgs e) 
    { 
     // Code that runs when a session ends. 
     // Note: The Session_End event is raised only when the sessionstate mode 
     // is set to InProc in the Web.config file. If session mode is set to StateServer 
     // or SQLServer, the event is not raised. 

    } 

</script> 

test1頁我已經編寫下面這樣的按鈕單擊事件:

protected void Button1_Click(object sender, EventArgs e) 
{ 

    string url = Page.GetRouteUrl("test2-testurl", new { category = "laptops" }); 
    Response.RedirectToRoute(url); 

} 
+0

感謝編輯佑 – 2013-03-12 10:43:59

回答

0

也許試試這個(刪除'test2'):

routes.MapPageRoute("test2-testurl", "{category}", "~/test2.aspx"); 

更新: 嘗試只是爲了這樣重定向到頁面

Response.Redirect("page2/laptops"); 

例子:

// add route 
routes.MapPageRoute("ad-view", "view/{ad-id}", "~/ad_view.aspx"); 
// on page I usualy bind values in repeater to links like this: 
<asp:HyperLink ID="TitleHL" NavigateUrl='<%# "view/" + Eval("ad_id") %>' runat="server"> 
// to redirect from code-behind i'll use: 
Responce.Redirect("view/" + ad_id); 
+0

仍流汗更新的答案同樣的錯誤尤金 – 2013-03-12 11:40:49

+0

; - ) – 2013-03-12 11:52:21

+0

我是否需要在web.config文件中隨編程一起添加一些內容,因爲我仍然收到無法找到資源的錯誤。 – 2013-03-12 12:44:50