Server.Transfer throws Error executing child reque

2019-02-11 16:15发布

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?

7条回答
Anthone
2楼-- · 2019-02-11 16:43

I had this same problem, and discovered it was to do with the relative paths of where the Server.Transfer is running and where you are redirecting to. In my case, this was executing in a sub-directory, so @ray's answer (adding ../ to the start of the URL) worked. However, when I then executed in the directory above, the same thing happened. Therefore, I changed to using a rooted path:

Server.Transfer("~/errorpage.aspx")
查看更多
登录 后发表回答