如果遭遇ASP.Net应用程序莫名其妙退出问题,可以在Global.asax中添加下列代码记录Application Pool退出原因
void Application_End(object sender, EventArgs e)
{
HttpRuntime runtime = (HttpRuntime) typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime"
, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField
, null
, null
, null
);
if (runtime == null) return;
string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage"
, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField
, null
, runtime
, null
);
string shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack"
, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField
, null
, runtime
, null
);
EventLog log = new EventLog();
log.Source = "XXX";
log.WriteEntry(String.Format("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}"
, shutDownMessage
, shutDownStack
)
, EventLogEntryType.Warning
);
}
此代码将退出的原因记录到了XXX这个 Event Source, 所以需要在服务器上创建此 Event Source.
eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO XXX /D "XXX"
当Application Pool正常退出时,日志中就会记录有Application Pool退出的原因。无外乎下面几种情况:
1. web.config被修改 / 2. 即时编译的*.cs文件被修改(一般在App_Code中) / 3.Bin目录被更新 / 4.*.aspx,*.ascx,*.master文件被修改的个数超过阀值 / 5. 长时间的Idle超过阀值
下面的日志显示的是由于App_Code目录被修改导致的退出
The following information was included with the event:
_shutDownMessage=Change Notification for critical directories.
App_Code dir change or directory rename
HostingEnvironment initiated shutdown
Change Notification for critical directories.
App_Code dir change or directory rename
HostingEnvironment caused shutdown
_shutDownStack= at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)
at System.Web.HttpRuntime.OnCriticalDirectoryChange(Object sender, FileChangeEvent e)
at System.Web.FileChangesMonitor.OnCriticaldirChange(Object sender, FileChangeEvent e)
at System.Web.DirectoryMonitor.FireNotifications()
at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
the message resource is present but the message is not found in the string/message table
同时最好加上日志记录Application的启动事件。
protected void Application_Start(object sender, EventArgs e)
{
EventLog log = new EventLog();
log.Source = "XXX";
log.WriteEntry("Application Pool Starting..." , EventLogEntryType.Information);
}
通过 eventvwr, 可以分析Application Pool重启的原因。如果Application Pool是由于崩溃导致异常退出,这个时候Application_End是不会被触发的。但同时在 ASP.Net的系统日志中还是能够查到异常退出的原因。
分享到:
相关推荐
ASP.net Ajax电子教程/不错的教程。由于上传文件MB的限制、所以分为两部分 ASP.net Ajax电子教程1 ASP.net Ajax电子教程2
书 名:ASP.NET从入门到精通<br/>作 者:chris payne<br/>翻 译: 赵斌张 滨义董 清波 译<br/>出版社:人民邮电出版社<br/>出版日期:2002年<br/><br/>本书章节简列:<br/>1:ASP.NET初步<br/>2.创建asp.net页面<br/>...
ASP.NET iPhone Controls 2/2
ASP.NET iPhone Controls 1/2
《ASP.NET项目开发案例全程实录(第2版)》所有案例源码,不包括视频,如要包括视频的,请下载以下所有文件再解压: 《ASP.NET项目开发案例全程实录(第2版)》随书光盘.part01.rar ...
通过研究三层体系结构模式的应用系统设计方法,特别详细地阐述基于ASP.NET技术进行开发B/S三层结构应用系统的主要设计思想和步骤,并结合一个项目的开发过程作为示例进行分析与设计,具体地介绍利用ASP.NET面向对象技术...
ASP.NET从入门到精通(1/3)<br/><br/>书 名:ASP.NET从入门到精通<br/>作 者:chris payne<br/>翻 译: 赵斌张 滨义董 清波 译<br/>出版社:人民邮电出版社<br/>出版日期:2002年<br/><br/>本书章节简列:<br/>1:ASP...
ASP.NET从入门到精通(1/3)<br/><br/>书 名:ASP.NET从入门到精通<br/>作 者:chris payne<br/>翻 译: 赵斌张 滨义董 清波 译<br/>出版社:人民邮电出版社<br/>出版日期:2002年<br/><br/>本书章节简列:<br/>1:ASP...
这是一个简单的在Android客户端连接Asp.Net进行上传或下载的示例,在Android客户端以psot形式发送请求到Asp.Net服务器端,服务器端接收到请求参数后判断是上传还是下载,并进行相应处理。 示例中传输的数据未实体类...
asp.net 全国省/市/县 3级联动 ajax实现 附带access数据库asp.net 全国省/市/县 3级联动 ajax实现 附带access数据库
Componentone Studio 2009 v3 Full Studio for ASP.NET 3/4 Componentone Studio 2009 v3 Full含注册机 OS: Win32 | 483 MB Componentone Studio 2009 v3 Full Studio for Mobile ...
至理:精通ASP.NET3.5网络开发源代码
Studio for ASP.NET 1/4含注册机 Componentone Studio 2009 v3 Full OS: Win32 | 483 MB Componentone Studio 2009 v3 Full Studio for Mobile http://download.csdn.net/source/1926145 Componentone Studio 2009 ...
Componentone Studio 2009 v3 Full Studio for ASP.NET 2/4 Componentone Studio 2009 v3 Full 含注册机 OS: Win32 | 483 MB Componentone Studio 2009 v3 Full Studio for Mobile ...
Componentone Studio 2009 v3 Full Studio for ASP.NET 4/4 含注册机 Componentone Studio 2009 v3 Full OS: Win32 | 483 MB Componentone Studio 2009 v3 Full Studio for Mobile ...
An ASP.NET Gallery for Sharing Photos, Video, Audio and Other Media
asp.net/java/javascript/sql笔试题库(有答案)
ASP.NET Core Application Development: Building an application in four sprints (Developer Reference) By: James Chambers; David Paquette; Simon Timms Publisher: Microsoft Press Active Server Pages ASP...
2.最新版本的ASP.NET.CORE.Web API 3.实现dbfrist和code 。 4.博客链接:https://blog.csdn.net/EAyayaya/article/details/124048491 5. 不是MVC方式 6.Entity Framework Core Entity Framework Core.Tools Entity ...
系统名称:双鱼林asp.net图书信息管理系统学习版 系统功能: (1)系统分两种身份:管理员和读者,读者可以分为不同的类型,每种类型借书天数和续借天数都不一样! (2)图书管理:添加图书类别,维护图书类别,登记图书...