我在的.ascx一些代码,看起来像这样:内嵌代码将导致ASP.NET插入当前页面内500页
<%
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,但我想评论说,它并没有解决它
这不是正常行为 - 整个页面将在任何*响应发送到客户端之前执行。所以它不能发送给你一个部分响应,然后发送一个不同的响应。你是否通过AJAX加载其他页面?似乎您的问题缺少[MCVE](http://stackoverflow.com/help/mcve)。 – mason