C# 对于特定类型的运行时异常,异常处理失败

C# 对于特定类型的运行时异常,异常处理失败,c#,asp.net,windows,iis-7,C#,Asp.net,Windows,Iis 7,我有下面的代码,对我来说很好,并且在我的web应用程序的“应用程序出错”事件中使用。但是,我有一个运行时错误,成功地转义了这段代码: “事件代码:4010事件消息:发生未处理的安全异常。” 这意味着我没有堆栈跟踪,无法查看导致此问题的原因。如何修改代码以捕获此运行时错误 public void AddLogEntry(HttpRequest httpRequest, Exception ex) { LogData.LogEntry entry = new LogDat

我有下面的代码,对我来说很好,并且在我的web应用程序的“应用程序出错”事件中使用。但是,我有一个运行时错误,成功地转义了这段代码:

“事件代码:4010事件消息:发生未处理的安全异常。”

这意味着我没有堆栈跟踪,无法查看导致此问题的原因。如何修改代码以捕获此运行时错误

  public void AddLogEntry(HttpRequest httpRequest, Exception ex)
    {
        LogData.LogEntry entry = new LogData.LogEntry();

        //PageTitle
        entry.PageTitle = httpRequest.Url.AbsolutePath;

        //Date
        entry.Created = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
     //   httpRequest
        //Error
        entry.Error = ex.ToString();

        //HTTP-Values
        foreach (string key in httpRequest.ServerVariables)
        {
            string value = httpRequest.ServerVariables[key];
            if (value != string.Empty)
            {
                if (key == "ALL_HTTP" || key == "ALL_RAW")
                    value = value.Replace(System.Environment.NewLine, ", ");
                entry.ServerVariables.Add(key + ": " + value);

            }
        }


        if (_data.LogEntries.Count > 500)
            _data.LogEntries.Clear();
        _data.LogEntries.Add(entry);

        //Send e-mail to developers
       SendEmail(entry.ToString());
    }

我在缓存中看到过这种情况,用户没有从缓存中重新加载项的权限。好吧,我以前听过这种情况,但是为什么运行应用程序池的用户可以加载缓存,但在缓存过期时无法重新加载?为什么这个错误会从应用程序错误处理机制中消失呢?好的,我发现并将尝试这个:这个运行时错误很可能是在加强缓存思想的主线程(应用程序线程)中产生的。