[英]Routing in ASP.net Web forms with id parameters
我在我的 RouteConfig.cs 中注冊了這個 MapPageRoute
routes.MapPageRoute(
"ProfileRoute",
"Profile/{userid}",
"~/Profile.aspx"
);
這就是我使用 id 參數重定向到個人資料頁面的方式(從登錄到個人資料)
Response.Redirect(GetRouteUrl("ProfileRoute", new { userid = usersign.Text }));
但是,它顯示錯誤“'/' 應用程序中的服務器錯誤”。 和“找不到資源”請求的 URL 看起來像“請求的 URL:/Profile/id”
我之前使用過以下 Route 方法
Response.Redirect(String.Format("Profile.aspx?id={0}", id));
但我想將其更改為更好、更穩定的路由方法,它在某種程度上類似於 MVC 路由。
我可以在我的代碼中修復哪些錯誤? 我怎樣才能在 Web forms 中實現我的目標?
我自己想通了。 我從 RouteConfig.cs 中刪除了以下代碼
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
它奏效了
我不需要這段代碼(現在),因為我還沒有創建任何控制器。 除非我需要它們,否則我想這段代碼對我的項目來說並沒有多大必要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.