Server.TransferRequest()

M

Matt Winward

Hi all.

On requests for a parent web application, and when certain conditions
match, I need to load pages from a child web application. I've been
playing around with various methods, including RewritePath and
Server.Transfer, but these each have problems of their own.

Reading up on TransferRequest, this seems like the ideal solution
where the request is sent back through the IIS pipeline and the user
will see the results from the sub application, but the URL will remain
unchanged .. perfect.

The problem is that when I try this, the URL *does* get changed. I may
as well have just done a Response.Redirect! Obviously I'm doing
something wrong. Anyone know what it might be??


Thanks,

Matt
 
M

Matt Winward

I've just put together a very simple test solution with the following
files:

Default.aspx
Test.aspx
MyModule.cs

I've added MyModule to the Web.Config and made it TransferRequest to
Test.aspx.

This works perfectly and loads the content of Test.aspx under the
guise of Default.aspx. I'm not sure why this works and my main
solution doesn't, but I'll keep looking into it; I'm sure it will turn
out to be something stupidly simple!
 
G

George Ter-Saakov

I would recommend using HttpContext.RewritePath
I am successfully using it.
so if you have unresolved problems let us know and we'll help you to solve
them



George.
 
M

Matt Winward

Hi George.

I tried using RewritePath but ran into some problems. Basically, it
looked as though the application was still running from the root, so
all image and css paths were broken. Is there a way around this?

If I remember correctly, I think it also led to problems with the sub
application not being able to find its assemblies because it was still
working from the root and I ended up playing with assembly probing,
which didn't get very far.

After looking into this further, I've discovered it was something
silly .. I had a redirect in a handler in the sub application! I've
sorted that out and now I'm just left with some messed up image and
css paths, so I'm updating images etc to point to /SubApplication/,
which seems to be working.

So I've got the client URL as http://domain/fakefolder/ loading
http://domain/subapp/fakefolder/ and the subapp has a handler that
actually loads http://domain/subapp/default.aspx with some querystring
info.

Finally getting somewhere. Although this approach would mean upgrading
the servers to IIS7.

Can I ask why you prefer using RewritePath?
 
G

George Ter-Saakov

I see now...
You can not go outside of application scope with RewritePath.

you are going to face a problem with postback.
Try to add form and a button. Then click a button....

Check the URL in your address bar... You will see the problem.
the reason is that ASP.NET <form> grabs a current url and put it into action
property.
So your form tag will look like
<form action="http://domain/subapp/default.aspx"> which is probably not what
you want..

There are 2 solutions
1. Create your own class derived from HtmlForm and us it.
2. RewritePath back. Then form will have rewritten path in the action
property.
Althoug i am not sure you will be able to rewrite it to
http://domain/fakefolder/



George.
 
M

Matt Winward

If I understand you correctly, I think it's the other way around.

Let's say that a customer is called Green Gate Solutions. We provide
them with a content managed minisite and the URL is http://www.ourdomain.com/greengate.

We already have our main web application at the web root. To handle
these content managed minisites, we'll have a sub web application
called (for example) SubWebApp.

The main root application will have a module that watches the
requested URL. If it has a subfolder that matches a customer subfolder
name, then this happens in the background:

http://www.domain.com/GreenGate ====> http://www.domain.com/SubWebApp/GreenGate

Then within the SubWebApp, a handler picks up the request, sees that
the GreenGate minisite has been requested, and loads the content using
http://www.domain.com/SubWebApp/Default.aspx?rid=X where X is the ID
for the customer.

I found that RewritePath didn't really work at all. Because it thought
it was still running from the root, it lost assemblies and fell apart
completely.

I did try moving the SubWebApp up to the root, giving it a subfolder
for it's pages and using Server.Transfer() instead and this *almost*
worked. Everything was fine except for a marquee ajax control that got
very confused and I couldn't work out why.

At the moment I'm trying Server.TransferRequest on IIS7 and after
renaming loads of links I reckon it's going to work. But the big
downside is that it means waiting until we can upgrade the servers to
IIS7.

Putting the app in the root folder will mean major clashes with the
main website, and considering it has a handler that handles every aspx
request, it'll probably mean a big performance hit as well.

I'll keep you posted with any further progress, but any suggestions
are welcome! :)

Matt
 

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

Top