时间:2016-02-15 22:28 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出】,下面是详细的讲解!
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
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);
}
}
}
关于在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出的用户互动如下:
相关问题:WIN7已安装Microsoft .NET Framework 2.0真三国无...
答:凉宫全能1.8印发给你们,希望对大家有用。我祝游戏愉快! (92989 ****) 读宫春日的改性剂处理: 1宫春日的程序需要Microsoft NET Framework 2.0或以上版本的支持,请在使用前进行确认。微软。 NET Framework是一个Microsoft Windows组件,Wind... >>详细
相关问题:VS2008编译调试都没有问题,发布到IIS后出现找不到...
答:先确认你的发布文件是否都在你发布的根目录下,然后再确认你发布的网站属性中.NET版本是否和你编译的版本是否是一致,一般都这些小毛病 >>详细
相关问题:我安装了Microsoft.NET Framework v2.0但是在添加...
答:没明白你的意思 你安装 FW2.0是想干什么呢? 启用IIS吗? >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【asp】asp.net ubb使用代码-net-ubb使用
- 【默认图片】图片不存在使用默认图片代替的实例
- 【asp】asp.net 页面转向 Response.Redirect Ser
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【MVC5】MVC 5 第一章 创建MVC 5 web应用程序-net
- 【MVC】一个简单MVC5 + EF6示例分享-EF6实例-MVC5
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
