Extensionless SEO Friendly with Asp.net webforms

2019-06-12 03:37发布

问题:

How to get extension less and without query string SEO friendly URL for asp.net web forms.?

回答1:

I have found out a very good article Here

It is a very good blog post written on how to redirect urls which contain query strings as extension less seo friendly urls.

One method of doing it by including Global.asax into the application.

Here is the example.

Include Global.asax into the application.

<%@ Import Namespace="System.Web.Routing" %>

inside global.asax file

void registerroute(RouteCollection routes)
    {
        routes.MapPageRoute(
            "Home-Route",
            "Home",
            "~/Default.aspx"
            );
}

Which will map the home page or default page

For Query string urls like http://xyz.com/page.aspx?id=about

routes.MapPageRoute(
          "Page-Route",
          "Pages/{page}",
          "~/page.aspx"
          ); 

Then call this registerroute() inside application start event under Global.asax

 void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        registerroute(RouteTable.Routes);
    }

Then to access the query string inside pages.

string pg = Page.RouteData.Values["page"] as string;