2012-07-28 71 views
9

我想通過以下這在我的Web窗體應用程序添加路由:ASP.NET路由在Global.asax中

http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application

我已經添加的路由在我的Global.asax文件像所以:

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("", "/WebsiteName/{combinedPin}", "~/Default.aspx"); 
} 

然後我嘗試在本地訪問我的網站是這樣的:

的http://本地主機:12345/WebsiteName/test36u

但我得到一個資源找不到消息,所以我不認爲我的路線是正確的。任何人都可以看到我的代碼有問題嗎?

任何指針將不勝感激。

感謝

回答

5

你並不需要指定網站的名稱作爲路線的一部分,嘗試使用此代碼:

routes.MapPageRoute("", "{combinedPin}", "~/Default.aspx"); 

與上面的代碼,你的鏈接看起來像:

http://localhost:12345/WebsiteName/test36u 

如果您但是目的是使用戶訪問使用命名細分網站:WebsiteName然後使用:

routes.MapPageRoute("", "WebsiteName/{combinedPin}", "~/Default.aspx"); 

但在先例代碼的用戶將有權訪問自己的資源,如下所示:(可能不是預期,雖然結果)

http://localhost:12345/WebsiteName/WebsiteName/test36u 
+0

感謝Jupaol。我仍然能夠訪問Request.QueryString [「combinedPin」]?我想能夠檢查,看它是否存在錯誤處理... – 2012-07-29 02:43:25

+1

忽略我,我想我可以這樣做:Page.RouteData.Values [「combinedPin」] – 2012-07-29 02:46:43