what is the url rewriting?how to rewrite the url? give any
example

Answer Posted / chinnu

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.

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does php work?

534


How do you compare strings in java?

513


Is null in php?

530


How many php functions are there?

545


Tell me what does the array operator '===' means?

526






What is a php session?

568


What is the difference between substr() and strstr()?

780


Tell me what is the meaning of a final class and a final method?

525


How do I check environment variables?

527


Write syntax to open a file in php?

518


how to track user logged out or not? when a user is idle?

527


What is the use of strip_tags() method?

549


Why would we use === instead of ==?

8349


What is the difference between require_once and require in php?

551


How long is csrf token?

539