获取"对象引用未设置为实例"在HttpContext.Current.Application中

时间:2014-07-18 04:18:03

标签: httpcontext

我很难弄清楚如何解决这个问题。我希望在服务器关闭时将错误捕获并将页面重定向到Maintenance.aspx。但它在HttpContext.Current.Application["ErrorCode"].ToString();收到错误。请帮我解决这个问题......

非常感谢。

try{
// method here
}
 catch (Exception ex)
       {
            Panel1.Visible = true;
            string statuscode = HttpContext.Current.Application["ErrorCode"].ToString(); //Getting error here!
            if (statuscode != null || statuscode != string.Empty)
            {
                if (statuscode == "500")
                {
                    lblDetailMsg.Text = "<b>Error Page- <b> " + HttpContext.Current.Application["ErrorPage"].ToString() + " <br /> <b>Error Message-</b> The Requested Page was not found.";
                    Response.Redirect("Maintenance.aspx");
                }
            }

        }

0 个答案:

没有答案