现在的位置: 首页 > 综合 > 正文

当ajax出错时,自动跳转到在web.cofing中设置的错误页

2012年12月17日 ⁄ 综合 ⁄ 共 686字 ⁄ 字号 评论关闭
aspx
    <form id="form1" runat="server">
        
<asp:ScriptManager ID="ScriptManager1" runat="server" AllowCustomErrorsRedirect="true">
        
</asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            
<ContentTemplate>
                
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            
</ContentTemplate>
        
</asp:UpdatePanel>
        

    </form>

cs

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
throw new Exception();
    }

在web.config中<system.web>内加入

<customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>

抱歉!评论已关闭.