468,553 Members | 1,458 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,553 developers. It's quick & easy.

Q: HttpContext.RewritePath

Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning server side), or is the client in anyway affected?

Thanks
Nov 18 '05 #1
8 1574
From what I understand is it rewrite the URL appear on your browser.

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:Od*************@TK2MSFTNGP10.phx.gbl...
Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning server side), or is the client in anyway affected?

Thanks

Nov 18 '05 #2
RewritePath is used when you are using some url munging scheme.

say you want your urls to look like

http://mysite.com/myapp/tv/listproducts.aspx
http://mysite.com/myapp/10001/listproducts.aspx

instead of

http://mysite.com/myapp/listproducts.aspx?type=tv
http://mysite.com/myapp/listproducts...stomerid=10001

you could write a httpmodule using RewritePath translate the incoming url,
to valid path to the apsx page.

-- bruce (sqlwork.com)
"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:Od*************@TK2MSFTNGP10.phx.gbl...
Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning server side), or is the client in anyway affected?

Thanks

Nov 18 '05 #3
Let say browser sent a request for /mysite/my.aspx
HttpContext.Rewrite kicks in before that aspx processed and rewrites it to
/mysite/template1/notmy.aspx.

From now on the ASP.NET engine will see that request as if came to
/mysite/template1/notmy.aspx pretty much ignoring the original request for
/mysite/my.aspx

You see??? You just rewrote the URL.

The client is unaffected in anyway (ALMOST). Since it thinks that it still
gets the HTML from /mysite/my.aspx
Guess why i have that almost there? I was amazed that practically any
article or sample of using that HttpContext.Rewrite does not mention one
small but important problem

The <form> action will be /mysite/template1/notmy.aspx
So the next time you click submit button you will clearly see in the browser
full url.
Of course there is an easy workaround "In a page_load event rewrite url back
to the original"

Another thing is you must be careful with path you specify to images or js
files.
If you use relative path browser will convert it to full path and send
request to the server. And since browser has no idea that URL was rewritten
it will ask for
/mysite/my.gif not /mysite/template1/my.gif. Which might be not what you
expected.
So it's probably better to specify the full path for images and ohter
related to the page files.
George.
"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:Od*************@TK2MSFTNGP10.phx.gbl...
Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning server side), or is the client in anyway affected?

Thanks

Nov 18 '05 #4
I see. I am most interested to find out what the behavior is on the client
side.
I think now I understand why when I used HttpContext.RewritePath on my
initial post(!IsPostBack), the postback url was changed to the rewritten
path via form action attribute.
And as for non-aspx page resources, it's because those are handled by IIS
not ASP.NET, isn't it?

Bear with me one more time.
The sdk doc states: "RewritePath is used in cookieless session state." How
might RewritePath be used in a cookieless session state?

Thank you.
Jiho

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl...
Let say browser sent a request for /mysite/my.aspx
HttpContext.Rewrite kicks in before that aspx processed and rewrites it to
/mysite/template1/notmy.aspx.

From now on the ASP.NET engine will see that request as if came to
/mysite/template1/notmy.aspx pretty much ignoring the original request for
/mysite/my.aspx

You see??? You just rewrote the URL.

The client is unaffected in anyway (ALMOST). Since it thinks that it still
gets the HTML from /mysite/my.aspx
Guess why i have that almost there? I was amazed that practically any
article or sample of using that HttpContext.Rewrite does not mention one
small but important problem

The <form> action will be /mysite/template1/notmy.aspx
So the next time you click submit button you will clearly see in the browser full url.
Of course there is an easy workaround "In a page_load event rewrite url back to the original"

Another thing is you must be careful with path you specify to images or js
files.
If you use relative path browser will convert it to full path and send
request to the server. And since browser has no idea that URL was rewritten it will ask for
/mysite/my.gif not /mysite/template1/my.gif. Which might be not what you
expected.
So it's probably better to specify the full path for images and ohter
related to the page files.
George.
"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:Od*************@TK2MSFTNGP10.phx.gbl...
Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning server side), or is the client in anyway affected?

Thanks


Nov 18 '05 #5
Have you ever saw the burl of the cookieless browser?
Here is an example if you did not (Go to http://mappoint.msn.com)

It will redirect you automatically to something like
http://mappoint.msn.com/(mmagffm234v...v55)/Home.aspx

This (mmagffm234v5vpmbik0oev55) is your session identifier.

I hope you do not believe that this folder (mmagffm234v5vpmbik0oev55)
actually exist on the server.

When you hit that URL asp engine rewrites url to
http://mappoint.msn.com/Home.aspx and setting correctly session object to
the one identified by (mmagffm234v5vpmbik0oev55)

You still have to watch out how do you reference images.
Since browser is not aware of those rewrites and will try to retrieve an
image from
http://mappoint.msn.com/(mmagffm234v...0oev55)/my.gif if you used
relative path to it.
George.

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I see. I am most interested to find out what the behavior is on the client side.
I think now I understand why when I used HttpContext.RewritePath on my
initial post(!IsPostBack), the postback url was changed to the rewritten
path via form action attribute.
And as for non-aspx page resources, it's because those are handled by IIS
not ASP.NET, isn't it?

Bear with me one more time.
The sdk doc states: "RewritePath is used in cookieless session state." How might RewritePath be used in a cookieless session state?

Thank you.
Jiho

Nov 18 '05 #6
Thanks George, for that example.

I've actually seen them before and I've also seen this variation:

http://mappoint.msn.com/Home.aspx/mm...v5vpmbik0oev55 (Not at mappoint,
this probably won't work here)

So what is the difference between doing it this way instead of using the
querystring like this? To be precise, what benefits do you gain?

http://mappoint.msn.com/Home.aspx?si...v5vpmbik0oev55

You've been most helpful.
Jiho

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl...
Have you ever saw the burl of the cookieless browser?
Here is an example if you did not (Go to http://mappoint.msn.com)

It will redirect you automatically to something like
http://mappoint.msn.com/(mmagffm234v...v55)/Home.aspx

This (mmagffm234v5vpmbik0oev55) is your session identifier.

I hope you do not believe that this folder (mmagffm234v5vpmbik0oev55)
actually exist on the server.

When you hit that URL asp engine rewrites url to
http://mappoint.msn.com/Home.aspx and setting correctly session object to
the one identified by (mmagffm234v5vpmbik0oev55)

You still have to watch out how do you reference images.
Since browser is not aware of those rewrites and will try to retrieve an
image from
http://mappoint.msn.com/(mmagffm234v...0oev55)/my.gif if you used
relative path to it.
George.

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I see. I am most interested to find out what the behavior is on the

client
side.
I think now I understand why when I used HttpContext.RewritePath on my
initial post(!IsPostBack), the postback url was changed to the rewritten
path via form action attribute.
And as for non-aspx page resources, it's because those are handled by IIS not ASP.NET, isn't it?

Bear with me one more time.
The sdk doc states: "RewritePath is used in cookieless session state."

How
might RewritePath be used in a cookieless session state?

Thank you.
Jiho


Nov 18 '05 #7
As for embed session into the url. you will get the benefit that all relative links to other pages will automatically carryover session id.

Let say you have a page http://mappoint.msn.com/{seesionid}/mypage.aspx
and you have a link <a href="mypage2.aspx">

The sessionid will be automaticly transfered to mypage2.aspx

The overal benefit of URL rewriting is to create human readable urls.

George
My Site - Body Jewelry
"Jiho Han" <ji******@infinityinfo.com> wrote in message news:e$**************@TK2MSFTNGP10.phx.gbl...
Thanks George, for that example.

I've actually seen them before and I've also seen this variation:

http://mappoint.msn.com/Home.aspx/mm...v5vpmbik0oev55 (Not at mappoint,
this probably won't work here)

So what is the difference between doing it this way instead of using the
querystring like this? To be precise, what benefits do you gain?

http://mappoint.msn.com/Home.aspx?si...v5vpmbik0oev55

You've been most helpful.
Jiho

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl...
Have you ever saw the burl of the cookieless browser?
Here is an example if you did not (Go to http://mappoint.msn.com)

It will redirect you automatically to something like
http://mappoint.msn.com/(mmagffm234v...v55)/Home.aspx

This (mmagffm234v5vpmbik0oev55) is your session identifier.

I hope you do not believe that this folder (mmagffm234v5vpmbik0oev55)
actually exist on the server.

When you hit that URL asp engine rewrites url to
http://mappoint.msn.com/Home.aspx and setting correctly session object to
the one identified by (mmagffm234v5vpmbik0oev55)

You still have to watch out how do you reference images.
Since browser is not aware of those rewrites and will try to retrieve an
image from
http://mappoint.msn.com/(mmagffm234v...0oev55)/my.gif if you used
relative path to it.
George.

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I see. I am most interested to find out what the behavior is on the

client
side.
I think now I understand why when I used HttpContext.RewritePath on my
initial post(!IsPostBack), the postback url was changed to the rewritten
path via form action attribute.
And as for non-aspx page resources, it's because those are handled by IIS not ASP.NET, isn't it?

Bear with me one more time.
The sdk doc states: "RewritePath is used in cookieless session state."

How
might RewritePath be used in a cookieless session state?

Thank you.
Jiho


Nov 18 '05 #8
Oh I see what you mean by the session info being carried over to other pages without attaching querystring to every page.

Thanks.
"George" <no****@hotmail.com> wrote in message news:ev****************@TK2MSFTNGP11.phx.gbl...
As for embed session into the url. you will get the benefit that all relative links to other pages will automatically carryover session id.

Let say you have a page http://mappoint.msn.com/{seesionid}/mypage.aspx
and you have a link <a href="mypage2.aspx">

The sessionid will be automaticly transfered to mypage2.aspx

The overal benefit of URL rewriting is to create human readable urls.

George
My Site - Body Jewelry
"Jiho Han" <ji******@infinityinfo.com> wrote in message news:e$**************@TK2MSFTNGP10.phx.gbl...
Thanks George, for that example.

I've actually seen them before and I've also seen this variation:

http://mappoint.msn.com/Home.aspx/mm...v5vpmbik0oev55 (Not at mappoint,
this probably won't work here)

So what is the difference between doing it this way instead of using the
querystring like this? To be precise, what benefits do you gain?

http://mappoint.msn.com/Home.aspx?si...v5vpmbik0oev55

You've been most helpful.
Jiho

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl...
Have you ever saw the burl of the cookieless browser?
Here is an example if you did not (Go to http://mappoint.msn.com)

It will redirect you automatically to something like
http://mappoint.msn.com/(mmagffm234v...v55)/Home.aspx

This (mmagffm234v5vpmbik0oev55) is your session identifier.

I hope you do not believe that this folder (mmagffm234v5vpmbik0oev55)
actually exist on the server.

When you hit that URL asp engine rewrites url to
http://mappoint.msn.com/Home.aspx and setting correctly session object to
the one identified by (mmagffm234v5vpmbik0oev55)

You still have to watch out how do you reference images.
Since browser is not aware of those rewrites and will try to retrieve an
image from
http://mappoint.msn.com/(mmagffm234v...0oev55)/my.gif if you used
relative path to it.
George.

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I see. I am most interested to find out what the behavior is on the

client
side.
I think now I understand why when I used HttpContext.RewritePath on my
initial post(!IsPostBack), the postback url was changed to the rewritten
path via form action attribute.
And as for non-aspx page resources, it's because those are handled by IIS not ASP.NET, isn't it?

Bear with me one more time.
The sdk doc states: "RewritePath is used in cookieless session state."

How
might RewritePath be used in a cookieless session state?

Thank you.
Jiho


Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Guadala Harry | last post: by
1 post views Thread by marcmiles | last post: by
15 posts views Thread by James Higgs | last post: by
3 posts views Thread by asanford | last post: by
2 posts views Thread by Steven Nagy | last post: by
1 post views Thread by mmorrison93 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.