Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
C#/ASP:如何处理母版页中页面的异常?_C#_Asp.net_Exception Handling_Master Pages - Fatal编程技术网

C#/ASP:如何处理母版页中页面的异常?

C#/ASP:如何处理母版页中页面的异常?,c#,asp.net,exception-handling,master-pages,C#,Asp.net,Exception Handling,Master Pages,我想知道在母版页中是否有处理异常的方法。让我们假设一个非常简单的情况: Site.Master: protected void Page_Init(object sender, EventArgs e) { try { DoStuffFromChildPage(); } catch (Exception ex) { Response.Write(ex.Mess

我想知道在母版页中是否有处理异常的方法。让我们假设一个非常简单的情况:

Site.Master:

protected void Page_Init(object sender, EventArgs e)
    {
        try
        {
            DoStuffFromChildPage(); 
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

    }
Default.aspx:

protected void Page_Init(object sender, EventArgs e)
    {
        throw new Exception("Test Exception");
    }

这只是我的想法/概念的简单概述。我试图阻止在每个使用master的页面中编写try..catch代码块。

我不久前研究过这个问题,但从未找到任何真正好的方法。所有其他选择最终都变得比实际情况更复杂。您可以考虑根本不使用try/catch,而只使用自定义错误页面,但我不确定这是您想要的

您还可以创建自己的中央异常处理程序,并且当您仍然在页面和母版页中放置try/catch时,至少它们将在相同的位置进行处理