Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 错误页未呈现_Asp.net_Routing_Global Asax_Custom Error Pages_Server.transfer - Fatal编程技术网

Asp.net 错误页未呈现

Asp.net 错误页未呈现,asp.net,routing,global-asax,custom-error-pages,server.transfer,Asp.net,Routing,Global Asax,Custom Error Pages,Server.transfer,因此,我设置了global.asax应用程序_Error()事件来处理错误,然后将Server.Transfer()发送到自定义错误页面。当抛出异常时,我可以通过应用程序错误事件观察代码,然后进入我的自定义错误页面的页面加载()事件,并在没有错误的情况下浏览所有代码;然而,我的错误页面永远不会结束渲染。它只是停留在我的页面上,看起来什么都没发生。为什么我的错误页面没有呈现?下面是我的应用程序错误事件以及错误页面的页面加载事件的代码 protected void Application_E

因此,我设置了global.asax应用程序_Error()事件来处理错误,然后将Server.Transfer()发送到自定义错误页面。当抛出异常时,我可以通过应用程序错误事件观察代码,然后进入我的自定义错误页面的页面加载()事件,并在没有错误的情况下浏览所有代码;然而,我的错误页面永远不会结束渲染。它只是停留在我的页面上,看起来什么都没发生。为什么我的错误页面没有呈现?下面是我的应用程序错误事件以及错误页面的页面加载事件的代码

    protected void Application_Error(object sender, EventArgs e)
    {
        Exception ex = HttpContext.Current.Server.GetLastError();

        if (ex is HttpUnhandledException && ex.InnerException != null)
            ex = ex.InnerException;

        if (ex != null)
        {
            Guid errorID = Guid.NewGuid();
            log.Error(string.Format("=====WEBSITE ERROR===== Error ID: {0}", errorID), ex);
            Server.Transfer(string.Format("~/Pages/error.aspx?id={0}", errorID));
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        string errorID = Request.QueryString["id"];
        Exception ex = HttpContext.Current.Server.GetLastError();
        if (ex is HttpUnhandledException && ex.InnerException != null)
            ex = ex.InnerException;

        lblErrorID.Text = errorID;

        if (ex != null)
        {
            lblErrorMessage.Text = ex.Message;
            lblStackTrace.Text = ex.StackTrace.Replace("\n", "<br/>");
            plcStackTrace.Visible = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["displayStackTrace"]);
        }
        else
            plcErrorData.Visible = false;
    }
受保护的无效应用程序\u错误(对象发送方,事件参数e)
{
异常ex=HttpContext.Current.Server.GetLastError();
if(ex为HttpUnhandledException&&ex.InnerException!=null)
ex=ex.InnerException;
如果(ex!=null)
{
Guid errorID=Guid.NewGuid();
log.Error(string.Format(“=======网站错误=====错误ID:{0}”,errorID),例如);
Server.Transfer(string.Format(“~/Pages/error.aspx?id={0}”,errorID));
}
}
受保护的无效页面加载(对象发送方、事件参数e)
{
字符串errorID=Request.QueryString[“id”];
异常ex=HttpContext.Current.Server.GetLastError();
if(ex为HttpUnhandledException&&ex.InnerException!=null)
ex=ex.InnerException;
lblErrorID.Text=errorID;
如果(ex!=null)
{
lblErrorMessage.Text=ex.Message;
lblStackTrace.Text=ex.StackTrace.Replace(“\n”和“
”); plcStackTrace.Visible=bool.Parse(System.Configuration.ConfigurationManager.AppSettings[“displayStackTrace”]); } 其他的 plcErrorData.Visible=false; }

另外值得注意的是,我正在通过Application_Start事件和RouteConfig类进行自定义路由。这不应该影响这一点,因为我在另一个网站上做了完全相同的事情,它就像一个符咒一样工作。

处理异常后,您必须清除它。只需调用Server.ClearError()

受保护的无效页面加载(对象发送方,事件参数e)
{
字符串errorID=Request.QueryString[“id”];
异常ex=HttpContext.Current.Server.GetLastError();
if(ex为HttpUnhandledException&&ex.InnerException!=null)
ex=ex.InnerException;
//这很有效
ClearError();
lblErrorID.Text=errorID;
如果(ex!=null)
{
lblErrorMessage.Text=ex.Message;
lblStackTrace.Text=ex.StackTrace.Replace(“\n”和“
”); plcStackTrace.Visible=bool.Parse(System.Configuration.ConfigurationManager.AppSettings[“displayStackTrace”]); } 其他的 plcErrorData.Visible=false; }
不,这实际上不起作用。即使使用Server.ClearError()调用,我仍然看到相同的行为。这很奇怪。我复制了它,服务器完成了这个任务。我可能没有考虑到路线。
protected void Page_Load(object sender, EventArgs e)
{
    string errorID = Request.QueryString["id"];
    Exception ex = HttpContext.Current.Server.GetLastError();
    if (ex is HttpUnhandledException && ex.InnerException != null)
        ex = ex.InnerException;

     //This works  
     Server.ClearError();

    lblErrorID.Text = errorID;

    if (ex != null)
    {
        lblErrorMessage.Text = ex.Message;
        lblStackTrace.Text = ex.StackTrace.Replace("\n", "<br/>");
        plcStackTrace.Visible = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["displayStackTrace"]);
    }
    else
        plcErrorData.Visible = false;
}