程序产生异常后或者其他错误不想让它跳到代码行进行显示。想让它跳转到指定的页面中去。在网上看了看说是修改web.config。但是没有成功代码如下:
<customErrors mode="On" defaultRedirect="ApplicationError.aspx">
      
    </customErrors>
ApplicationError.aspx页面是建在和web.config通一个目录下的。页面里什么也没写。第二次是上面的没动,紧接着建立了Global.asax写了如下代码 protected void Application_Error(object sender, EventArgs e)
        {
            Exception error = Server.GetLastError();            string err = "出错页面是:" + Request.Url.ToString() + "</br>";            err += "异常信息:" + error.Message + "</br>";            err += "Source:" + error.Source + "</br>";            err += "StackTrace:" + error.StackTrace + "</br>";            Server.ClearError();            Application["error"] = err;            System.Web.HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ApplicationPath + "ApplicationError.aspx");
        }但还是没成功,那位能告诉我该怎么实现吗?谢谢了

解决方案 »

  1.   

    FORM认证
      

  2.   

    我说的是各种异常bug不仅仅是表单验证,而且是整个项目的错误提示都不显示。
    我不知道是我没看懂您给的链接的方法还是您没有完全理解我的意思。
      

  3.   


    <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly">
        <!--发生500错误,跳转到InternalError.htm页面-->
        <error statusCode="500" redirect="InternalError.htm"/>
        </customErrors>mode改成
    RemoteOnly表示在访问者和服务器在同一台电脑上就显示详细错误,否则根据错误代码做不同的跳转。
    no我自己也不太理解,就不误人子弟
    Off向所有访问者显示详细错误,不论访问者是否和服务器在同一台电脑上。
      

  4.   


    <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly">
        <!--发生500错误,跳转到InternalError.htm页面-->
        <error statusCode="500" redirect="InternalError.htm"/>
        <!--发生400错误,跳转到400.htm页面-->
        <error statusCode="400" redirect="400.htm"/>
        <!--发生400错误,跳转到400.htm页面-->
        <error statusCode="300" redirect="300.htm"/>
        </customErrors>一次类推
    mode为no时我想它显示的应该是类似"网站无法打开"的错误吧。
      

  5.   

    我想要的是所有错误都跳转到指定的页,不是指定的错误。
    http://msdn.microsoft.com/zh-cn/library/h0hfz6fc(VS.80).aspx
    这是微软官方的解释 。
    求解决办法
      

  6.   

    Exception异常显示特定页面,求高人指教
      

  7.   

    但是我想根据不同的错误产生不同的提示。if statusCode==404 错误提示是找不到页面 else if statusCode==500 连接不到数据库 。。
      

  8.   

    无语<customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly">
        <!--发生500错误,跳转到InternalError.htm页面-->
        <error statusCode="500" redirect="InternalError.htm"/>
        <!--发生400错误,跳转到400.htm页面-->
        <error statusCode="400" redirect="400.htm"/>
        <!--发生400错误,跳转到400.htm页面-->
        <error statusCode="300" redirect="300.htm"/>
        </customErrors>你可以在400.htm页面写上<h1>不存在的页面</h1>
    你可以在500.htm页面写上<h1>发生意外</h1
      

  9.   

    正解~~ WEB.CONFIG里面配置就行了~~
      

  10.   

    怪我的表达不够清楚。错误页面只有一个,根据后台判断错误类型后传值给前台,前台根据传过来的值显示不同的错误提示。例如:只有一个错误提示页:errors.aspx。 当400匹配的时候传个字符串“找不到指定的页”给前台errors.aspx。当500匹配的时候传个“未知问题”给前台errors.aspx。
      

  11.   


    要求过于理想化
    多几个html并不影响什么,应用错误和系统错误是不一样的
    也许global里可以代码实现?
      

  12.   

    没有关闭debug模式吧……webconfig里面 <compilation debug="true" defaultLanguage="c#"> 
      

  13.   

    http://apps.hi.baidu.com/share/detail/15609561