468,514 Members | 1,436 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

HttpContext.RewritePath - Form action changed

Hi all,

I have the following file:
~/cms/page.aspx

Normally, if you hit a url like http://localhost/MyApp/cms/page.aspx?PageID=32
... this would load content dynamically. No big deal, this is common
right?

So now I want to do some URL rewritting. I want to map:

http://localhost/MyApp/Test.aspx
to
http://localhost/MyApp/cms/page.aspx?PageID=32

(important to note that these are not in the same virtual folder)

So in "global.asax.cs" I write some code in "Application_BeginRequest"
to check if "Test.aspx" was requested, and if it was, rewrite it as
"cms/page.aspx?PageID=32". This also works fine.

The problem I am finding is that the page gets written with form tags
with action="page.aspx?PageID=32"

This of course is running under root so when it POSTS BACK, it
requests:
http://localhost/MyApp/page.aspx?PageID=32
not
http://localhost/MyApp/cms/page.aspx?PageID=32

... and I get an exception (resource not found).

So how can I make the form still use the original "fake" URL
(test.aspx) which would rewrite again on the post back and get the
real file?
Or is there another solution?

Thanks,
Steven

Apr 13 '07 #1
2 2780
Known problem with URL rewriting.
Not sure why but all articles I saw about url rewriting completely forget to
mention that. I guess speaks a lot about experience of those who wrote those
articles :)

solution rather simple. Rewrite it back first thing in a form Init method.

Here is how i do it (pseudo code)

_BeginRequest event
HttpContext.Items["originalrequest"] = Request.RawUrl;
HttpContext.UrlRewrite("my_new_path.aspx")
.....

Form_OnInit()
string sOriginalUrl = (string)HttpContext.Items["originalrequest"];
HttpContext.UrlRewrite("sOriginalUrl ")

....
George.


"Steven Nagy" <le*********@hotmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Hi all,

I have the following file:
~/cms/page.aspx

Normally, if you hit a url like
http://localhost/MyApp/cms/page.aspx?PageID=32
.. this would load content dynamically. No big deal, this is common
right?

So now I want to do some URL rewritting. I want to map:

http://localhost/MyApp/Test.aspx
to
http://localhost/MyApp/cms/page.aspx?PageID=32

(important to note that these are not in the same virtual folder)

So in "global.asax.cs" I write some code in "Application_BeginRequest"
to check if "Test.aspx" was requested, and if it was, rewrite it as
"cms/page.aspx?PageID=32". This also works fine.

The problem I am finding is that the page gets written with form tags
with action="page.aspx?PageID=32"

This of course is running under root so when it POSTS BACK, it
requests:
http://localhost/MyApp/page.aspx?PageID=32
not
http://localhost/MyApp/cms/page.aspx?PageID=32

.. and I get an exception (resource not found).

So how can I make the form still use the original "fake" URL
(test.aspx) which would rewrite again on the post back and get the
real file?
Or is there another solution?

Thanks,
Steven

Apr 13 '07 #2
Hi George,

Thanks for the response.
I'm at home now and I needed this for work.
I'll try it out on Monday and repost if still having problems.

Cheers,
Steven

On Apr 14, 1:05 am, "George Ter-Saakov" <gt-...@cardone.comwrote:
Known problem with URL rewriting.
Not sure why but all articles I saw about url rewriting completely forget to
mention that. I guess speaks a lot about experience of those who wrote those
articles :)

solution rather simple. Rewrite it back first thing in a form Init method.

Here is how i do it (pseudo code)

_BeginRequest event
HttpContext.Items["originalrequest"] = Request.RawUrl;
HttpContext.UrlRewrite("my_new_path.aspx")
....

Form_OnInit()
string sOriginalUrl = (string)HttpContext.Items["originalrequest"];
HttpContext.UrlRewrite("sOriginalUrl ")

...

George.
Apr 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Matt Howeson | last post: by
reply views Thread by Ayende Rahien | last post: by
5 posts views Thread by Guadala Harry | last post: by
8 posts views Thread by Jiho Han | 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
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.