![](/img/trans.png)
[英]ASP.NET 4.0 URL routing with two or multiple querystring parameters
[英]url rewriting in asp.net 4.0 with two parameters
我幾乎沒有動態生成的網址,例如
http://localhost:35228/begineercontrols?name=untitled&id=2
http://localhost:35228/begineercontrols?name=linkbutton&id=34
http://localhost:35228/begineercontrols?name=lablebutton&id=5
還有更多的東西,使用路由刪除了.aspx擴展名,這很好,現在我想使上面的URL更友好,例如
http://localhost:35228/begineercontrols/untitled/2
我如何為所有動態生成的URL實現這一目標,請在advace中幫助我!
在您的App_Start / RouteConfig.cs中,修改如下代碼
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
// Add Routes.
RegisterCustomRoutes(RouteTable.Routes);
}
private static void RegisterCustomRoutes(RouteCollection routes)
{
routes.MapPageRoute(
"begineercontrolsRoute",
"begineercontrols/{name}/{id}",
"~/begineercontrols.aspx"
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.