It’s very important for a web site to create SEO friendly URL’s and remove page extensions such as .aspx. When search engines look at a site, the first thing they analyze is the page URL which help them ascertain what the page content is about.
In ASP.NET application Routes can be used for this which are URL patterns used for processing requests and can be used to construct URLs dynamically. The Global.asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event in Global.asax.
In order to do so add Global Application Class (Global.asax) to your ASP.NET Web Application if it is not created yet.
The following example shows how to add a route.
protected void Application_Start(object sender, EventArgs e) { try { RegisterRoutes(RouteTable.Routes); } catch (Exception ex) { // Log Exception here } } protected static void RegisterRoutes(RouteCollection routes) { if (routes != null) { RouteTable.Routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler())); routes.MapPageRoute("DefaultRoute", "", "~/Default.aspx"); routes.MapPageRoute("SomePage", "somepage", "~/SomePage.aspx"); } }
The marked line adds a route for default landing page of the web site so a website URL such as http://somewebsite.com/Default.aspx will be changed to http://somewebsite.com.
Similarly http://somewebsite.com/SomePage.aspx will be changed to http://somewebsite.com/somepage in the example which is a lot better now.