天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

在 .NET Framework 2.0 中未處理的異常導致基于 ASP.NET 的應用程序意外退出

但是,系統日志中可能會記錄類似于以下內容的事件消息:
事件類型:警告
事件來源:W3SVC
事件類別:無
事件 ID: 1009
日期: 9/28/2005
時間:3:18:11
PM 用戶:N/A
計算機:IIS-SERVER
描述:
應用程序池“DefaultAppPool”提供服務的進程意外終止。進程 ID 是“2548”。進程退出代碼是“0xe0434f4d”。
而且,應用程序日志中可能會記錄類似于以下內容的事件消息:
事件類型:錯誤
事件來源:.NET Runtime 2.0 錯誤報告
事件類別:無
事件 ID: 5000
日期: 9/28/2005
時間:3:18:02 PM
用戶:N/A
計算機:IIS-SERVER
描述:
EventType clr20r3, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 app_web_7437ep-9, P5 0.0.0.0, P6 433b1670, P7 9, P8 a, P9 system.exception, P10 NIL.


解決辦法:

方法 1修改 IHttpModule 對象的源代碼,以便將異常信息記錄到應用程序日志中。記錄的信息將包含以下內容:
出現異常的虛擬目錄路徑
異常名稱
消息
堆棧跟蹤
要修改 IHttpModule 對象,請按照下列步驟操作。
注意:此代碼將會在應用程序日志中記錄事件類型為“錯誤”且事件來源為“ASP.NET 2.0.50727.0”的消息。要測試模塊,可以請求使用 ThreadPool.QueueUserWorkItem 方法的 ASP.NET 頁,以調用引發未處理的異常的方法。
將下面的代碼放在名為 UnhandledExceptionModule.cs 的文件中。
復制代碼 代碼如下:
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Web;
namespace WebMonitor {
public class UnhandledExceptionModule: IHttpModule {
static int _unhandledExceptionCount = 0;
static string _sourceName = null;
static object _initLock = new object();
static bool _initialized = false;
public void Init(HttpApplication app) {
// Do this one time for each AppDomain.
if (!_initialized) {
lock (_initLock) {
if (!_initialized) {
string webenginePath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "webengine.dll");
if (!File.Exists(webenginePath)) {
throw new Exception(String.Format(CultureInfo.InvariantCulture,
"Failed to locate webengine.dll at '{0}'. This module requires .NET Framework 2.0.",
webenginePath));
}
FileVersionInfo ver = FileVersionInfo.GetVersionInfo(webenginePath);
_sourceName = string.Format(CultureInfo.InvariantCulture, "ASP.NET {0}.{1}.{2}.0",
ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart);
if (!EventLog.SourceExists(_sourceName)) {
throw new Exception(String.Format(CultureInfo.InvariantCulture,
"There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.",
_sourceName));
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
_initialized = true;
}
}
}
}
public void Dispose() {
}
void OnUnhandledException(object o, UnhandledExceptionEventArgs e) {
// Let this occur one time for each AppDomain.
if (Interlocked.Exchange(ref _unhandledExceptionCount, 1) != 0)
return;
StringBuilder message = new StringBuilder("/r/n/r/nUnhandledException logged by UnhandledExceptionModule.dll:/r/n/r/nappId=");
string appId = (string) AppDomain.CurrentDomain.GetData(".appId");
if (appId != null) {
message.Append(appId);
}

Exception currentException = null;
for (currentException = (Exception)e.ExceptionObject; currentException != null; currentException = currentException.InnerException) {
message.AppendFormat("/r/n/r/ntype={0}/r/n/r/nmessage={1}/r/n/r/nstack=/r/n{2}/r/n/r/n",
currentException.GetType().FullName,
currentException.Message,
currentException.StackTrace);
}
EventLog Log = new EventLog();
Log.Source = _sourceName;
Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
}
}
}


將 UnhandledExceptionModule.cs 文件保存到下面的文件夾中:
C:/Program Files/Microsoft Visual Studio 8/VC
打開 Microsoft Visual Studio 2005 命令提示符窗口。
鍵入 sn.exe -k key.snk,然后按 Enter。
鍵入 csc /t:library /r:system.web.dll,system.dll /keyfile:key.snk UnhandledExceptionModule.cs,然后按 Enter。
鍵入 gacutil.exe /if UnhandledExceptionModule.dll,然后按 Enter。
鍵入 ngen install UnhandledExceptionModule.dll,然后按 Enter。
鍵入 gacutil /l UnhandledExceptionModule,然后按 Enter 以顯示 UnhandledExceptionModule 文件的強名稱。
9. 將下面的代碼添加到基于 ASP.NET應用程序的 Web.config 文件中。
<add name="UnhandledExceptionModule"
    type="WebMonitor.UnhandledExceptionModule, <strong name>" />

方法 2將未處理異常策略更改回 .NET Framework 1.1 和 .NET Framework 1.0 中發生的默認行為。
注意:我們不建議您更改默認行為。如果忽略異常,應用程序可能會泄漏資源并放棄鎖定。
要啟用這種默認行為,請將下面的代碼添加到位于以下文件夾的 ASPNET.config 文件中:
復制代碼 代碼如下:
%WINDIR%/Microsoft.NET/Framework/v2.0.50727
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
</configuration>

AspNet技術在 .NET Framework 2.0 中未處理的異常導致基于 ASP.NET 的應用程序意外退出,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 动漫AV纯肉无码AV电影网 | 美女扒开腿让男生桶免费看动态图 | a级销魂美女 | 色偷偷综合网 | 99久久久精品免费观看国产 | 国内极度色诱视频网站 | xxxxhdvideos动漫 | 动漫美女无衣 | 恋夜影视列表免费安卓手机版 | 67194成在线观看免费 | 国产精品久久久久久亚洲影视 | 亚洲中字幕永久在线观看 | 女的把腿张开男的往里面插 | 伊人激情综合网 | 99国产精品久久 | 在线 自拍 综合 亚洲 欧美 | 国产亚洲精品欧洲在线视频 | 豆奶视频在线高清观看 | 亚洲精品一卡二卡三卡四卡2021 | 99国产亚洲精品无码成人 | 产传媒61国产免费 | 亚洲AV无码一区二区三区乱子伦 | 久久伊人免费 | 欧美成人momandson | 高H高肉强J短篇校园 | 综合亚洲桃色第一影院 | 妖精视频一区二区免费 | 爆操日本美女 | 色偷偷成人网免费视频男人的天堂 | 亚洲免费三级电影 | 柏木舞子在线 | 亚洲国产精品久久又爽黄A片 | 奇米狠狠干 | BL低喘贯穿顶弄老师H | 国产一区二区三区国产精品 | 在线不卡中文字幕 | 伦理片飘花免费影院 | 动漫女生的逼 | 极品少妇高潮XXXXX | 武侠艳妇屈辱的张开双腿 | xxxx88|