473,480 Members | 4,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2972
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2231
by: Matt Howeson | last post by:
Some time ago I posted a request for help with a problem I was having sometime ago whereby a 404 error would result if any access to the Querystring had been made before the Context.Rewritepath is...
0
2640
by: Ayende Rahien | last post by:
I've a very annoying problem, I'm using Application_BeginRequest() and Context.RewritePath to hide query strings. The problem that I've is that a form that I submit to /Comments/17.aspx has form...
5
2721
by: Guadala Harry | last post by:
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:...
8
1833
by: Jiho Han | last post by:
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...
1
1629
by: marcmiles | last post by:
It looks like postbacks cause a problem with HttpContext.RewritePath. I've read about the two solutions below, but the first one seems extensive, and the scond one seems too easy. I sent an email...
15
6666
by: James Higgs | last post by:
For a long time, our product has had a "vanity URLs" feature where nice URLs are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath(). This has worked beautifully...
3
2895
by: asanford | last post by:
I want to create an ASP.NET web application that receives a form POST message, inspects the data, and reroutes the request to one of many different servers. I wrote an IHttpModule which...
0
1416
by: cpnet | last post by:
I was playing around with Beta 2 of VS2005, .NET 2.0, and built an IHttpModule do allow me to have nice URL's in my web app. It was working great. I had a URL like: ...
1
5145
by: jbitz | last post by:
Hi, This has got me really baffled. This has got me really baffled. When I run Dim url As String = HttpContext.Current.Request.Url.AbsolutePath.ToLower from Application_beginRequest in...
0
7040
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.