ASP.NET Web Forms URL Rewriting capability

2020-08-01 06:11发布

问题:

I have a very simple question, rather I am just curious.

I have about 2000 pages of the url format somewebsite.com/ShowProduct.aspx?ID=223 . This particular url has a page title as 'Walking sticks for elders made from durable steel'.

Can I use URL Rewriting to convert this to a url like somewebsite.com/walking-stick-for-elders ? Also will I have do it dynamically for 2000 pages or is there any expression that can be used?

回答1:

You need to have some thing which uniquely indentifies URLs just like Stackoverflow does it.

ASP.NET Web Forms URL Rewriting capability

See this question URL - Where from URL you get its for question then there is a question id and then description. I suggest you do the same.

If you are using ASP.NET 4.0 or higher version then you can do that type of URL routing very easily.

Like from this URL - http://weblogs.asp.net/scottgu/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series

There is also a asp.net friendly URL package form where you can write URls.

http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx

RouteConfig.RegisterRoutes(RouteTable.Routes);


回答2:

If each product name is unique and stored inside the database you can easily route each SEO friendly URL to productID without manually inputing a new route in the Routing table.