【发布时间】:2017-03-31 18:30:18
【问题描述】:
我在 .ascx 中有一些代码,如下所示:
<%
int a = 0;
int b = 5;
int c = b/a;
%>
如预期的那样抛出 500 错误(除以 0)。
CustomErrors 看起来像这样
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="/500.aspx" />
</customErrors>
我尝试访问的页面呈现混乱。查看源代码,我看到了正常页面的一半,然后是 500 页面。
<div class="mapTextOverlay" style="width:448px;padding-left:232.96px;">
[main page abruptly ends here and the 500 page starts]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head"><title>
500
</title>
[etc.]
所以服务器传输发生在页面渲染的中间。
在出现 500 错误的情况下,如何防止部分页面呈现的可能性?
- 这只会发生在内联代码中,如果错误在代码隐藏中,错误会正常显示。
- 代码中没有调用 Response.Flush()
- Response.BufferOutput 为真
- 代码正在设置 Response.Filter,但我尝试对此进行评论,但没有修复它
【问题讨论】:
-
这不是正常行为 - 整个页面将在 any 响应发送到客户端之前执行。所以它不能向您发送部分响应然后发送不同的响应。您是否通过 AJAX 加载其他页面?好像您的问题缺少MCVE。
标签: asp.net webforms custom-errors