Server.Transfer 抛出执行子请求时出错。如何解决?

发布于 2024-08-24 05:40:03 字数 577 浏览 12 评论 0原文

我在 C# 2.0 中有一个 HttpModule 来处理抛出的异常。每当抛出异常时,就会调用带有一些查询字符串的错误页面(aspx)。它是通过Server.Transfer()完成的。

但是当控件尝试执行Server.Transfer()时,会抛出以下异常:

执行 [pagename].aspx 的子请求时出错。

Request.Redirect() 工作正常。

我尝试在请求传输到的页面的 Page 指令中设置 EnableViewStateMac="false" 。但问题仍然存在。

这是我尝试过的代码:

string errorPage = "errorpage.aspx?id=" + someErrorId
HttpContext.Current.Server.Transfer(errorPage,true);

知道如何解决这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

多情出卖 2024-08-31 05:40:03

我找到了 Server.Transfer() 的替代方案,

我用

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

它解决了这个问题。

I found an alternative to Server.Transfer()

I used

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

This solved the issue.

﹉夏雨初晴づ 2024-08-31 05:40:03

我在 OnPreRequestHandlerExecute 事件中连接到请求管道,发现我无法使用 Server.Transfer,因为它在执行子请求时抛出了与您相同的错误。

使用 HttpContext.Current.RewritePath 不起作用,因为它似乎被忽略,并且我没有被重定向到任何地方。

如果您使用的是 IIS 7 及更高版本,则可以使用 Server.TransferRequest 来代替,这对我来说很有效。

此答案涵盖了两种方法之间的差异:TransferRequest 与 Transfer in ASP.Net< /a>

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

难如初 2024-08-31 05:40:03

我的修复方法有所不同:

在线查询产生了这篇 Microsoft 知识库文章,其中指出解决方案是使用 Response .Redirect而不是Server.Transfer

我更改了命令并得到了更准确的“404 错误消息”,而不是神秘的“执行子请求时出错”消息。

这导致我检查了重定向字符串,我发现我的路径已关闭。

我将传输字符串从“ErrorPage.aspx”修复为“../ErrorPage.aspx”(注意路径更改)并且 Server.Transfer 工作得很好。

My fix was different:

An online query produced this Microsoft Knowledge Base article which stated the resolution would be to use Response.Redirect instead of Server.Transfer.

I changed the command and got a more accurate "404 Error Message" instead of the cryptic "Error executing child request" message.

That led me to inspect the redirect string and I noticed my path was off.

I fixed the Transfer String from "ErrorPage.aspx" to "../ErrorPage.aspx" (notice the path change) and Server.Transfer worked just fine.

娇柔作态 2024-08-31 05:40:03

如果您在调试过程中碰巧在 VS.NET IDE 中看到此异常,请至少执行一次并按 F5 继续调试。就我而言,实际页面确实呈现了 ASP.NET 异常,这确实导致了问题。就我而言,我有一个格式不正确的 asp:ChangePassword 控件,实际上导致了“执行子请求时出错”异常。

If you happen to see this exception occur in the VS.NET IDE during debug, go ahead at least once and press F5 to continue debugging. In my case, the actual page did render with the ASP.NET exception that was really causing the issue. In my case I had an incorrectly formatted asp:ChangePassword control that was actually causing the "Error executing child request" exception.

じее 2024-08-31 05:40:03

我将 Server.Transfer 更改为 Server.TransferRequest,然后我得到了真正的异常。这是由于引用了不正确的 ReportViewer 版本而出现的问题。

I changed Server.Transfer for Server.TransferRequest, then I've got the real exception behind. It was a problem with a reference to an incorrect ReportViewer version.

她比我温柔 2024-08-31 05:40:03

Server.Transfer("mywebpage.aspx") 似乎仅在会话已存在时才起作用。

如果没有启动会话,则会抛出此错误,因此您必须使用Response.Redirect或其他方法。

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.

小…楫夜泊 2024-08-31 05:40:03

我遇到了同样的问题,发现这与 Server.Transfer 运行位置和重定向到位置的相对路径有关。就我而言,这是在子目录中执行的,因此 @ray 的答案(将 ../ 添加到 URL 的开头)有效。然而,当我在上面的目录中执行时,发生了同样的事情。因此,我改为使用根路径:

Server.Transfer("~/errorpage.aspx")

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")
王权女流氓 2024-08-31 05:40:03

这不是一个错误,而是设计使然。请参阅http://support.microsoft.com/kb/320439

It isn't a bug, it is by design. See http://support.microsoft.com/kb/320439

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文