Extensionless SEO Friendly with Asp.net webforms

2019-06-12 03:48发布

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

1条回答
孤傲高冷的网名
2楼-- · 2019-06-12 04:09

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;
查看更多
登录 后发表回答