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

后端 未结 8 1771
小蘑菇
小蘑菇 2020-12-17 08:36

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 i

相关标签:
8条回答
  • 2020-12-17 09:02

    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

    0 讨论(0)
  • 2020-12-17 09:07

    Server.Transfer("mywebpage.aspx") seems to work only when a session already exists.

    If there is no Session started it throws this error so you must use Response.Redirect or another method.

    0 讨论(0)
提交回复
热议问题