ASP.net WebForms无扩展URL
据我所知,在ASP.net 4.0中,URL路由已被合并到Web表单中。我能做这样的事情真是太好了:ASP.net WebForms无扩展URL,asp.net,url-rewriting,routing,url-routing,Asp.net,Url Rewriting,Routing,Url Routing,据我所知,在ASP.net 4.0中,URL路由已被合并到Web表单中。我能做这样的事情真是太好了: void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("Category", "list/{id}/{name}", "~
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Category", "list/{id}/{name}", "~/category.aspx");
routes.MapPageRoute("Product", "item/{id}/{name}", "~/product.aspx");
}
但是有没有一种内置的方法可以让我在不为每个文件手动添加路由的情况下,将无扩展名的URL路由到它们的.aspx对应文件?例如:
account/login => account/login.aspx
contact-us => contact-us.aspx
谢谢
我在路线的末尾添加了以下内容,作为一个“一网打尽”的规则,它似乎起到了作用
routes.MapPageRoute("Default", "{*file}", "~/{file}.aspx");
您可以像在MVC中一样使用占位符 VB.NET
routes.MapPageRoute(
"ThreeLevels",
"{folder}/{file}/{id}",
"~/{folder}/{file}.aspx", True,
New RouteValueDictionary From {
{"folder", "Home"},
{"file", "Default"},
{"id", Nothing}
})
C#
routes.MapPageRoute(
"ThreeLevels",
"{folder}/{file}/{id}",
"~/{folder}/{file}.aspx", true,
new RouteValueDictionary {
{"folder", "Home"},
{"file", "Default"},
{"id", null}
});