how to transfer a request to a different page in IHttpModule (isapi like) class

D

daberelay

Hi,
I'm using IHttpModule class (added to GAC and machine.config) to get
requests of non existing pages in my web server and redirect them to
different pages, using the Context.Server.Transfer(Target) method.

i.e :
Original ==> http://myserver/notExist/HelloThere
to
Target ==> http://myserver/DoesExist/helloWorld.aspx

the problem is that the DoesExist application receive the request and
it's web.config shows the following error:

Configuration error:
"Parser Error Message: It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error can be caused by a virtual directory not being configured as an
application in IIS."

because notExist is not an appliaction in the web server, what should i
do to eliminate this problem?

Thanks!

Daberelay.
 
J

John Saunders

Hi,
I'm using IHttpModule class (added to GAC and machine.config) to get
requests of non existing pages in my web server and redirect them to
different pages, using the Context.Server.Transfer(Target) method.

i.e :
Original ==> http://myserver/notExist/HelloThere
to
Target ==> http://myserver/DoesExist/helloWorld.aspx

the problem is that the DoesExist application receive the request and
it's web.config shows the following error:

Configuration error:
"Parser Error Message: It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error can be caused by a virtual directory not being configured as an
application in IIS."

because notExist is not an appliaction in the web server, what should i
do to eliminate this problem?

Have you tried using Response.Redirect instead of Server.Transfer?
Server.Transfer is really meant to transfer from one HttpHandler to another,
and in your case, it seems that the handler doesn't exist (since the page
does not exist).

John Saunders
 
G

Guest

vbpj.com had a neat article on this about a year and half or two years ago.
Do a search on their site for "hierarchical url". It shows how to set up an
URL like:

mysite.com/dec/2004/28

to

mysite.com/pagehandler.aspx?id=12/28/2004

This is similar to what you want. And, there is sample code to download on
the site, if I remember correctly.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
D

daberelay

hey,
Thanks for the idea but Redirect causes a back and forth trip to the
client and also changes the url in the browser's address bar, what i
would like to do is cause the server to transfer without having to tell
the client about it.

any more ideas ?
 
D

daberelay

Hey there,
Thanks for the lead but it is suggesting using a workarround for asp
instead of ihttpmodule, and moreover it offers using the redirect
function instead of the server.transfer function. it's of no use to me
as i would like to change the response output without going to the
client machine.

DaberElay.
 
J

John Saunders

hey,
Thanks for the idea but Redirect causes a back and forth trip to the
client and also changes the url in the browser's address bar, what i
would like to do is cause the server to transfer without having to tell
the client about it.

any more ideas ?

One idea is that you _try_ redirect and see if it works. If it works, that
will tell you that the problem has to do with a difference between redirect
and Server.Transfer. If it doesn't work, that will tell you that the problem
has nothing to do with the difference between redirection and
Server.Transfer.

My concern is that there is nothing to transfer _from_ yet. In your code,
before your Server.Transfer, what kind of object is referenced by
Context.Handler?

John Saunders
 
J

John Saunders

Hey there,
Thanks for the lead but it is suggesting using a workarround for asp
instead of ihttpmodule, and moreover it offers using the redirect
function instead of the server.transfer function. it's of no use to me
as i would like to change the response output without going to the
client machine.

I was not offering it as a workaround. I was offering it as a diagnostic
technique.

John Saunders
 
D

daberelay

Sorry John,
I think there was a confusion here, the workarround line i wrote was
reffering another answer i got from George a. beamer...

as per your answer, i know redirect works (and anyhows i did it again
just to verify), because redirect doesn't touch the source of the
problem. redirect asks the client's browser to change it's request and
send it again...
the transfer function trys to do it without ever leaving the server
side.

as for the Context.Handler, its <undefined value> ( i.e. null reference
), what can we understand from this ? is there something i need to
instanciate first ?
Your concern is correct, there is nothing to transfer from just yet,
simply because the original request was for a page that doesn't exist.
Thanks for the responsiveness!

DaberElay.
 
J

John Saunders

Sorry John,
I think there was a confusion here, the workarround line i wrote was
reffering another answer i got from George a. beamer...

as per your answer, i know redirect works (and anyhows i did it again
just to verify), because redirect doesn't touch the source of the
problem. redirect asks the client's browser to change it's request and
send it again...
the transfer function trys to do it without ever leaving the server
side.

as for the Context.Handler, its <undefined value> ( i.e. null reference
), what can we understand from this ? is there something i need to
instanciate first ?
Your concern is correct, there is nothing to transfer from just yet,
simply because the original request was for a page that doesn't exist.
Thanks for the responsiveness!

I no longer recall the details of the original problem, but I know became
concerned because I suspected that Context.Handler would be null. I'm
frankly surprised that Server.Transfer works at all.

Have you looked into Url Rewriting using Context.RewritePath? I have used it
successfully in a similar situation.

John Saunders
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top