HttpContext.RewritePath

G

Guadala Harry

I'd really appreciate it if someone would give me a"plain English"
explanation of HttpContext.RewritePath(). I read the MSDN documentation, but
still don't understand it.

According to MSDN:
.... assigns an internal rewrite path. RewritePath allows for the URL that is
requested to differ from the internal path to the resource.

What does this mean? When would it be useful to have the paths differ ?

Thanks.
 
S

Steve C. Orr [MVP, MCSD]

It is especially useful with HTTPHandlers.
You could have fancy user-specific URLs such as this:
http://www.mysite.com/GuadalaHarry

But this would really be redirected internally (using RewritePath) to a more
normal path such as:
http://www.mysite.com/userpage.aspx?user=GuadalaHarry

The user would get to use the nice URL and wouldn't ever have to know that
you've really structured pages on your server differently than it appears.
This also gives you the freedom to change your file/folder structure on your
server in the future without changing the URLs that your users are already
familiar with.
 
G

Guest

This seems to be what I'm looking for too but I'm not sure where to use this

Where would you put a code that rewrites the path? In begin_request? Obviously the path has to be rewritten before the actual loading of a page begins, right

I would really appreciate a few lines of code just for example and where to put them for this to work

how to for example do what you wrote, when request URL is http://www.mysite.com/GuadalaHarry to have the application load http://www.mysite.com/userpage.aspx?user=GuadalaHarry instead

and is there any way for userpage.aspx to get the original request URL

----- Steve C. Orr [MVP, MCSD] wrote: ----

It is especially useful with HTTPHandlers
You could have fancy user-specific URLs such as this
http://www.mysite.com/GuadalaHarr

But this would really be redirected internally (using RewritePath) to a mor
normal path such as
http://www.mysite.com/userpage.aspx?user=GuadalaHarr

The user would get to use the nice URL and wouldn't ever have to know tha
you've really structured pages on your server differently than it appears
This also gives you the freedom to change your file/folder structure on you
server in the future without changing the URLs that your users are alread
familiar with
 
G

Guadala Harry

I saw an example of its use in a Page_Load event procedure (in a code-behind
module).

You can see it for yourself in the Community Starter Kit at
http://www.asp.net/Default.aspx?tabindex=9&tabid=47

HTH


Adrijan Josic said:
This seems to be what I'm looking for too but I'm not sure where to use this.

Where would you put a code that rewrites the path? In begin_request?
Obviously the path has to be rewritten before the actual loading of a page
begins, right?
I would really appreciate a few lines of code just for example and where to put them for this to work.

how to for example do what you wrote, when request URL is
http://www.mysite.com/GuadalaHarry to have the application load
http://www.mysite.com/userpage.aspx?user=GuadalaHarry instead?
and is there any way for userpage.aspx to get the original request URL?

----- Steve C. Orr [MVP, MCSD] wrote: -----

It is especially useful with HTTPHandlers.
You could have fancy user-specific URLs such as this:
http://www.mysite.com/GuadalaHarry

But this would really be redirected internally (using RewritePath) to a more
normal path such as:
http://www.mysite.com/userpage.aspx?user=GuadalaHarry

The user would get to use the nice URL and wouldn't ever have to know that
you've really structured pages on your server differently than it appears.
This also gives you the freedom to change your file/folder structure on your
server in the future without changing the URLs that your users are already
familiar with.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Guadala Harry said:
I'd really appreciate it if someone would give me a"plain English"
explanation of HttpContext.RewritePath(). I read the MSDN
documentation,
but
still don't understand it.
... assigns an internal rewrite path. RewritePath allows for the
URL that
is
requested to differ from the internal path to the resource.
 
G

Guadala Harry

Correction to my last post:
The example I saw was in the Page_Init event handler (not Page_Load).



Guadala Harry said:
I saw an example of its use in a Page_Load event procedure (in a code-behind
module).

You can see it for yourself in the Community Starter Kit at
http://www.asp.net/Default.aspx?tabindex=9&tabid=47

HTH


Adrijan Josic said:
This seems to be what I'm looking for too but I'm not sure where to use this.

Where would you put a code that rewrites the path? In begin_request?
Obviously the path has to be rewritten before the actual loading of a page
begins, right?
I would really appreciate a few lines of code just for example and where to put them for this to work.

how to for example do what you wrote, when request URL is
http://www.mysite.com/GuadalaHarry to have the application load
http://www.mysite.com/userpage.aspx?user=GuadalaHarry instead?
and is there any way for userpage.aspx to get the original request URL?

----- Steve C. Orr [MVP, MCSD] wrote: -----

It is especially useful with HTTPHandlers.
You could have fancy user-specific URLs such as this:
http://www.mysite.com/GuadalaHarry

But this would really be redirected internally (using RewritePath)
to
a more
normal path such as:
http://www.mysite.com/userpage.aspx?user=GuadalaHarry

The user would get to use the nice URL and wouldn't ever have to
know
that
you've really structured pages on your server differently than it appears.
This also gives you the freedom to change your file/folder
structure
on your
server in the future without changing the URLs that your users are already
familiar with.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



documentation, URL that
is
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,204
Latest member
LaverneRua

Latest Threads

Top