ASP.NET Webforms 4.0 Routing : How to get rid of physical urls
How would you accomplish these in ASP.NET Webforms 4.0 Routing;
- .aspx pages should not be accesible directly, pages should be accesible only with routes,
- S开发者_运维技巧tart page should be "/" or "/home" or something else, but not "Default.aspx".
Thanks.
You can specify ignore routes to ignore routing for your static handlers, for the static content part (though routing, if the static file exists, normally gets routed directly to the file no problem).
I believe the method you want to use though is MapPageRoute for web forms, which is for web forms. See this for examples: http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.mappageroute%28VS.100%29.aspx
Have you read Scott Guthrie's post introducing this subject?
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
You would do the following:
void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("nameofroute", "home/", "~/Default.aspx");
}
Adding parameters as necessary
精彩评论