如何解决global.aspx中Log.Error(ex)中的NullReferenceException异常

时间:2018-01-24 18:04:23

标签: c# asp.net asp.net-mvc asp.net-mvc-4

我的C#代码就像这样

    protected void Application_Error(object sender, EventArgs e)
    {
        var ex = Server.GetLastError();
        Log.Error(ex);
        var httpStatusCode = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : 500;

        var httpContext = ((MvcApplication)sender).Context;
        httpContext.ClearError();
        httpContext.Response.Clear();
        httpContext.Response.StatusCode = httpStatusCode;

        var shouldHandleException = true;
        Exception exceptionToReplace;         
    }

Log.Error(ex); 抛出此 System.NullReferenceException:对象引用未设置为对象实例错误导致var ex = 服务器.GetLastError(); 为空。我的问题是如何解决这个错误?任何信息都会对此有所帮助

enter image description here

0 个答案:

没有答案