I have a HttpModule
in C# 2.0 which handles exceptions thrown. Whenever the exception is thrown, an error page (aspx) with some querystring will be called. It is done through Server.Transfer()
.
But when the control tries to execute Server.Transfer()
, the following exception is thrown:
Error executing child request for [pagename].aspx.
Whereas Request.Redirect()
works fine.
I tried setting EnableViewStateMac="false"
in Page directive of the page to which request is transferred. Still problem persists.
Here is the code I tried:
string errorPage = "errorpage.aspx?id=" + someErrorId HttpContext.Current.Server.Transfer(errorPage,true);
Any idea how this can be resolved?
I found an alternative to Server.Transfer()
I used
HttpContext.Current.RewritePath("somefile.aspx");
This solved the issue.
I was hooking into the request pipeline in the OnPreRequestHandlerExecute event, and found I couldn't use Server.Transfer because it threw the same error as yours about executing a child request.
Using HttpContext.Current.RewritePath didn't work because it seemed to be ignored and I wasn't redirected anywhere.
If you're using IIS 7 and up, you can use Server.TransferRequest instead which did the trick for me.
The differences between the two methods are covered in this answer: TransferRequest vs Transfer in ASP.Net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With