Server.Execute & HttpHandler

S

Sam

My problem is that when I am trying to use
Server.Execute("Somehandler.ashx") I am getting HttpException.

[HttpException (0x80004005): Error executing child request for
Somehandler.ashx.]
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,
TextWriter writer, Boolean preserveForm, Boolean setPreviousPage,
VirtualPath path, VirtualPath filePath, String physPath, Exception
error, String queryStringOverride) +3179617
System.Web.HttpServerUtility.Execute(String path, TextWriter writer,
Boolean preserveForm) +747
System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) +56
System.Web.HttpServerUtility.Transfer(String path) +26
 
R

Rick Strahl [MVP]

According to the documentation HttpServerUtilty.Execute/Transfer only works
with pages... It simply may not work with handlers, because the redirect is
occurring from within the Page Handler framework. If you want to redirect to
a handler you need a physical redirect with Response.Redirect().

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog
 
S

Sam

Rick said:
According to the documentation HttpServerUtilty.Execute/Transfer only works
with pages... It simply may not work with handlers, because the redirect is
occurring from within the Page Handler framework. If you want to redirect to
a handler you need a physical redirect with Response.Redirect().

+++ Rick ---

I need to save Context.Items and it's impossible to redirect. Anyway my
application need only Server.Execute.

Quote from documentation:

"Executes the handler for the specified virtual path in the context of
the current request."

I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:

....
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
....
handler.ProcessRequest(...) // BUT It's only for Page instances (((
....
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString("Error_executing_child_request_for_handler",
objArray2), error);


Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)
 
C

Christopher Reed

I believe that the issue is that .ashx files are handled by the
SimpleHandlerFactory while .aspx files are handled by the
PageHandlerFactory. As Rick indicated in his post, the SimpleHandlerFactory
does not the redirect process that occurs with the transfer process because
this is embedded within the Page handler. It's not that the IHttpHandler is
prohibited; it's because the simple handler doesn't understand what a page
is necessarily.

Now, what are you trying to attempt using a simple handler file in place of
a page file?
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

Sam said:
Rick said:
According to the documentation HttpServerUtilty.Execute/Transfer only
works with pages... It simply may not work with handlers, because the
redirect is occurring from within the Page Handler framework. If you want
to redirect to a handler you need a physical redirect with
Response.Redirect().

+++ Rick ---

I need to save Context.Items and it's impossible to redirect. Anyway my
application need only Server.Execute.

Quote from documentation:

"Executes the handler for the specified virtual path in the context of the
current request."

I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:

...
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
...
handler.ProcessRequest(...) // BUT It's only for Page instances (((
...
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString("Error_executing_child_request_for_handler",
objArray2), error);


Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)
 
S

Sam

Christopher said:
I believe that the issue is that .ashx files are handled by the
SimpleHandlerFactory while .aspx files are handled by the
PageHandlerFactory. As Rick indicated in his post, the SimpleHandlerFactory
does not the redirect process that occurs with the transfer process because
this is embedded within the Page handler. It's not that the IHttpHandler is
prohibited; it's because the simple handler doesn't understand what a page
is necessarily.

Now, what are you trying to attempt using a simple handler file in place of
a page file?

It's not depended on Handler factories or something else. There is not
necessary ashx or aspx or jpg. It's a bug, and this bug must be fixed.
If method signature is: Server.Execute(IHttpHandler handler, ...) why I
have an exception here? Instead it there must be Server.Execute(Page
page,...) if handlers are prohibied. Is MS afraid that someone inherit
ASP.NET :)?

Please vote bugreport:

http://lab.msdn.microsoft.com/produ...edbackid=c1c80d3f-4835-4be4-aa0a-e0dc82b43356
 
S

Sam

Rick said:
According to the documentation HttpServerUtilty.Execute/Transfer only works
with pages... It simply may not work with handlers, because the redirect is
occurring from within the Page Handler framework. If you want to redirect to
a handler you need a physical redirect with Response.Redirect().

+++ Rick ---

I need to save Context.Items and it's impossible to direct redirect.
Anyway my
application need only Server.Execute.

Quote from documentation:

"Executes the handler for the specified virtual path in the context of
the current request."

I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:

....
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
....
handler.ProcessRequest(...) // BUT It's only for Page instances (((
....
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString("Error_executing_child_request_for_handler",
objArray2), error);


Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)

Next issue: Why I see the same behaviour with
Server.Execute(IHttphandler handler, ...)? Here is IHttpHandler as
method parameter.. and it don't work anyway. Why not System.Web.Page
instead of IHttpHandler, if handlers are prohibited? True is buried
within 3 lines above.

Quote from docs for HttpServerUtility.Execute(IHttpHandler, TextWriter,
Boolean):
"Executes the current request by using a custom HTTP handler that
implements the IHttpHandler interface. A TextWriter object captures
output from the page and specifies whether to clear the QueryString and
Form collections."
 
S

Sam

Rick said:
According to the documentation HttpServerUtilty.Execute/Transfer only works
with pages... It simply may not work with handlers, because the redirect is
occurring from within the Page Handler framework. If you want to redirect to
a handler you need a physical redirect with Response.Redirect().

+++ Rick ---

I need to save Context.Items and it's impossible to direct redirect.

Quote from documentation:

"Executes the handler for the specified virtual path in the context of
the current request."

I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:

....
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
....
handler.ProcessRequest(...) // BUT It's only for Page instances (((
....
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString("Error_executing_child_request_for_handler",
objArray2), error);


Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)

Next issue: Why I see the same behaviour with
Server.Execute(IHttphandler handler, ...)? Here is IHttpHandler as
method parameter.. and it don't work anyway. Why not System.Web.Page
instead of IHttpHandler, if handlers are prohibited? True is buried
within 3 lines above.

Quote from docs for HttpServerUtility.Execute(IHttpHandler, TextWriter,
Boolean):
"Executes the current request by using a custom HTTP handler that
implements the IHttpHandler interface. A TextWriter object captures
output from the page and specifies whether to clear the QueryString and
Form collections."
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top