Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.Transfer throws Error executing child request. How to resolve?

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?

like image 270
Amit Avatar asked Mar 02 '10 08:03

Amit


2 Answers

I found an alternative to Server.Transfer()

I used

 HttpContext.Current.RewritePath("somefile.aspx"); 

This solved the issue.

like image 83
Amit Avatar answered Sep 22 '22 12:09

Amit


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

like image 31
Karl Avatar answered Sep 25 '22 12:09

Karl