Best Online Resource For Non-Resident Indians      SEARCH COOLNRI.COM
 HOME  FORUMS  PORTALS & REVIEWS  RECIPES  INDIAN RESTAURANTS  GROCERY  CLASSIFIEDS  MOVIES / TV  CHAT  NEWS  HOROSCOPE  PAINTINGS  CONTACT  LOGIN
Welcome Guest Search | Active Topics | Members | Log In | Register

Very easy URL Rewriting Options
Salman
Posted: Monday, April 20, 2009 11:52:25 PM
Rank: Newbie
Groups: Member

Joined: 4/20/2009
Posts: 1
If you don't like having meaningless URL's for your visitors (i.e index.aspx?id=3&pid=3932), consider URL Re-writing. With URL rewriting, you can store all your content in the database while having user-friendly URL's. Here's a code snippet to do just this:


void Application_BeginRequest(Object sender, EventArgs e)
{
String strCurrentPath;
String strCustomPath;
strCurrentPath = Request.Path;
strCurrentPath = strCurrentPath.ToLower();
// the URL contains this folder name
if (strCurrentPath.IndexOf("/SomeSubFolder/") > -1)
{
strCustomPath = "getContent.aspx?id=" +
Path.GetFileNameWithoutExtension(strCurrentPath);

// rewrite the URL
Context.RewritePath(strCustomPath);
}
}



The getContent.aspx will take the page name as a parameter and do a lookup in the database and return the content for the page. I have left the details out because the point of the code snippet is to show how to rewrite the URL and get the data from the database.

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

COOLNRI.COM 2006-2012 |  TERMS OF USE |  PRIVACY STATEMENT |  SEARCH 
FinaMetric - Affordable Effective Project Management