Reputation: 13
I am using Asp.Net 4.0 and for generating SEO Friendly Urls I use Asp.Net Routing methods like;
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add("BikeSaleRoute", new Route
(
"bikes/sale",
new CustomRouteHandler("~/Contoso/Products/Details.aspx")
));
}
Handling it in Application_Start Method
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
What I am trying to write is a method using Asp.net Routing that can remove .aspx extensions from all my pages regardless of their directory level (even the starting page Default.aspx). Any help in this regard, please?
Upvotes: 1
Views: 1668
Reputation: 88
Your can use URL Re-writing in IIS or in Web.Config and can do by following code snippet, place following code in "Global.asax".
public static void RegisterRoutes(RouteCollection routeCollection) { routeCollection.MapPageRoute("RouteForDefault", "Default", "~/Default.aspx"); }
Good Luck
Upvotes: 1
Reputation: 627
If you want a general solution for all the pages in your project you can use the package here: http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
Otherwise you can use this in Global.asax for every page in your application:
public class Global : System.Web.HttpApplication
{
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("InteriorServices", "InteriorServices", "~/InteriorServices.aspx");
}
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
}
Upvotes: 0