ASP.NET, C# UrlRewriting - PathInfo
Change your URLs from
http://mysite.com/items.aspx?id=20&pname=TV
http://mysite.com/items.aspx?id=21&pname=DVD
http://mysite.com/items.aspx?id=22&pname=LCD ...
to
http://mysite.com/items.aspx/20/TV
http://mysite.com/items.aspx/21/DVD
http://mysite.com/items.aspx/22/LCD ...
How?
its simple
in Page1.aspx
<ul>
<li><a href="http://mysite.com/items.aspx/20/TV">TV</a></li>
<li><a href="http://mysite.com/items.aspx/21/DVD">DVD</a><
<li><a href="http://mysite.com/items.aspx/22/LCD">LCD</a></li>
</ul>
in items.aspx page
place this code
if (Request.PathInfo.Length == 0)
{ b1 = ""; b2 = ""; }
else
{
string pathinfo;
pathinfo = Request.PathInfo.Substring(1);
b1 = pathinfo.TrimEnd('/').Split('/')[0].ToString();
b2 = pathinfo.TrimEnd('/').Split('/')[1].ToString();
}
Use this kind of urls for beater search engine ranking. hope it helps ................. ;)
more info...
http://sharpertutorials.com/clean-url-structure-in-aspnet/
No comments:
Post a Comment