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;