在全局globa中的application error中处理的//页面不存在的错误
                //Context.Response.Clear();
                Response.Status = "404 Not Found";
                //Context.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotFound);
                Response.AddHeader("Location", "http://localhost:24531/web/serverErr.html");问题是
我在另一个分支数据库错误505时,跳转到一个html页面,请问如何保证505状态
使用redirect返回了200正确值。
使用Response.AddHeader也并没有跳转到servererr.html页面中。

解决方案 »

  1.   

    问题就是这里
    context.Response.Status = "404 Not Found";
                    //Context.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotFound);
                    context.Response.AddHeader("Location", "http://localhost:24531/web/serverErr.html");
    并没有跳转到目标页面,所以就redirect得
      

  2.   

    有没有什么办法可以改html中的status
      

  3.   

    错误处理主要代码:
     // 在出现未处理的错误时运行的代码        Exception ex = Server.GetLastError().GetBaseException();
            if (ex.GetType() == typeof(HttpException))
            {
                if (((HttpException)ex).GetHttpCode() == 404)
                {
                    //页面不存在的错误
                    //Context.Response.Clear();
                    Response.Status = "404 Not Found";
                    Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotFound);
                    Response.AppendHeader("Location", "http://localhost:24531/web/serverErr.html");
                }
                else
                {
                }
                
            }
            else if (ex.GetType() == typeof(System.Data.SqlClient.SqlException))
            {
                Context.Response.Redirect("serverErr.html");
            }
            else
            {
                
            }现在问题:
    404错误,还是在黄色页面,并没有跳到servererr.html
    500(数据库异常),跳转过去,但是状态这时由于是redirect,变成了200,监视程序捕捉的时非原页面的状态。
    我想:404可以跳到html页面,500最好也使用404的代码,并且保持住500的状态。
    记得在301跳转在aspx后台写实可以的,不知道在global中写是不是有些什么不同了。
    不愿意使用web.config配置和iis配置来实现这个问题
      

  4.   

    哎,使用Context.Response.writefile
      

  5.   


    直接跳不就行了
    Respone.Redirect("http://localhost:24531/web/serverErr.html");