使用两个参数在asp.net 4.0中重写url
我几乎没有像这样动态生成的URL使用两个参数在asp.net 4.0中重写url,asp.net,c#-4.0,url-rewriting,url-routing,Asp.net,C# 4.0,Url Rewriting,Url Routing,我几乎没有像这样动态生成的URL 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?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实现这一点请帮助我
谢谢你 在你的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"
);
}
如果我只能在没有任何参数的情况下调用,它会在路由中使用相同的规则定义吗?