我想在Web.config里设置一个错误提示页让所有页面出错后都跳转到这个错误提示页,应该怎么作比较好我现在是在每个页都加try-catch,捕获到错误后Response.Redirect("../../error.aspx");
这觉得这种作法不好,还要第个页都加try-catch,太麻烦了,有没有方便一点的方法

解决方案 »

  1.   


    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
      

  2.   

    web.config中
    <system.web>下
    <customErrors mode="Off" defaultRedirect="error.aspx">
    </customErrors>
    这样,不用try catch,只要页面出错,全部转向error.aspx
      

  3.   

    或者在global里边处理
     protected void Application_Error(object sender, System.EventArgs e)
    {
      //错误处理
    System.Exception current = Server.GetLastError();
    }
      

  4.   

    不好弄,但在 global.asax 里很方便:    void Application_Error(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder("<div style=\"font-size:12px;\"");
            sb.Append("出错信息:"); sb.Append(base.Server.GetLastError().InnerException.Message); 
            sb.Append("</div>");
            
            HttpContext.Current.Response.Write("<h5>An error occurred! </h5>");
            HttpContext.Current.Response.Write(sb.ToString());
            HttpContext.Current.Response.End();
        }
      

  5.   

    1.按不同错误码跳转到页面:
    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>
    2.所有错误统一跳到一个页面:
    <customErrors mode="Off" defaultRedirect="error.aspx" />但1,2都不好用在一些大项目中一般都要做到每个错误有具体错误提醒就如5楼的方法(这个也是最常用的方法):
    void Application_Error(object sender, EventArgs e) 
        { 
            StringBuilder sb = new StringBuilder(" <div style=\"font-size:12px;\""); 
            sb.Append("出错信息:"); sb.Append(base.Server.GetLastError().InnerException.Message); 
            sb.Append(" </div>"); 
            
            HttpContext.Current.Response.Write(" <h5>An error occurred! </h5>"); 
            HttpContext.Current.Response.Write(sb.ToString()); 
            HttpContext.Current.Response.End(); 
        }
      

  6.   

    不好使呀???????????????/
    我在
    web.config中 
    <system.web>下 
    <customErrors mode="Off" defaultRedirect="error.aspx"> 
    </customErrors> 
    然后建一个读库的错误页面,没有到error.aspx这个页面呀,是不是还有什么我没设置的
      

  7.   

    error.aspx
    你要建个这样一个页面啊
    没有怎么访问啊 
      

  8.   

    建立一个友好的,程序出错后,跳转的页面 比如:error.aspx
    <customErrors mode="On/Off/RemoteOnly" defaultRedirect="出错.aspx">
                <error statusCode="403" redirect="" />
                <error statusCode="404" redirect="未找到页面.aspx" />
            </customErrors>
      

  9.   

    我建error.aspx的页面了,但还是不跳转
    我用的是VS2005是不是不一样呀
      

  10.   

    我把mode 设为On就好使了,怎么回事
    <customErrors mode="On"  defaultRedirect="error.aspx"></customErrors>