这两天我一直被一个问题困扰,始终得不道解决,希望有达人能帮帮忙!问题如下:我发现在我的开发机器上调试所设计的网站时,只要有页面跳转、控件回发出现,Application_Start 就要被自动重复调用!原本我要在 Application_Start 方法里面添加我自己的用户信息装载功能的,如果这个问题不解决,就无法这样做。于是,为了验证是否运行条件下不会出现这个情况,我在 Application_Start 方法里面添加了这段代码:string path = @"D:\test.txt";
System.IO.SreamWriter sw;
if (System.IO.File.Exists(path))
sw = System.IO.File.AppendText(path);
else
sw = System.IO.File.CreateText(path);
sw.WriteLine("Application start");
sw.Flush();
sw.Close();
sw.Dispose();测试运行后,发现 "Application start" 在 test.txt 文件中出现多次。
然后,将网站发布到测试机,运行后发现只出现两次!这究竟是为什么?如何解决?
System.IO.SreamWriter sw;
if (System.IO.File.Exists(path))
sw = System.IO.File.AppendText(path);
else
sw = System.IO.File.CreateText(path);
sw.WriteLine("Application start");
sw.Flush();
sw.Close();
sw.Dispose();测试运行后,发现 "Application start" 在 test.txt 文件中出现多次。
然后,将网站发布到测试机,运行后发现只出现两次!这究竟是为什么?如何解决?
<%@ Application CodeFile="Global.asax.cs" Inherits="TestProj.Global" Language="C#" %>我的 web 应用程序都加了 namespace,在 Global.asax.cs 中这样书写:namespace TestPrj
{
public partial class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
string path = @"D:\test.txt";
System.IO.StreamWriter sw;
if ( System.IO.File.Exists( path ) )
sw = System.IO.File.AppendText( path );
else
sw = System.IO.File.CreateText( path );
sw.WriteLine( "Application start" );
sw.Flush();
sw.Close();
sw.Dispose(); this.clearApplication();
this.readAllUserInfo();
}
}
}
和是否内联没有关系,看样子是环境造成的:
你试试
1,关掉杀毒软件的实时监控功能
2,停止Indexing 服务(在管理工具-服务里面)
有没有修改到配置文件呢
===================================
我更改了配置的。machine.config<processModel autoConfig=true userName=system password=AutoGenerate />web.config 增加
<authorization>
<allow users="*"/>
</authorization><customErrors mode="Off"></customErrors>
修改:
<compilation debug="true">
web.config change/global.asax change/app_code directory change/a directory delete change, max-num-compilations reached quota/bin directory change
所以在Application_End里面把shutDown的原因写进应用程序日志,在事件察看器里面,很方便的就可以看到原因了,像这样的:
_shutDownMessage=“E:\test\2.0\WebSite2”的目录重命名更改通知。
WebSite2 dir change or directory rename
HostingEnvironment 导致关闭
这个比较有用的:)
参看http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx
=====
我详细的描述下我解决的过程。1。由 alien54155415() 的提醒,我意识到需要一个记录 Application_End() 的事件捕捉,于是,我在 C:\Winnt\Microsoft.Net\framework\...\config\web.config 里面新增了事件记录注册:
在 <healthMonitoring><rules> 配置节中,增加 <add name="Application Lifetime Events Default" eventName="Application Lifetime Events"
provider="EventLogProvider" profile="Default" minInstances="1"
maxLimit="Infinite" minInterval="00:01:00" custom="" />
(各位可以在 http://blogs.msdn.com/tess/archive/2006/08/02/686373.aspx 中获得详细参考)2. 启动应用程序,监视事件查看器。
我发现,每访问一次页面,会出现三个事件:
应用程序正在启动
应用程序正在编译
应用程序关闭,原因:bin 文件夹下文件被修改。 可以看出,造成关闭的原因就是访问时临时编译。为什么?3。在 VS 环境中,我检查了我的项目文件夹,在 bin 文件夹中有我引用的外部 dll 文件,会不会是这些访问时需要刷新造成的临时编译?
此时,我的 BIN 文件夹签出的。4。我签入 BIN,重新生成,然后访问,事件如下: 应用程序正在编译
应用程序启动问题解决了,各位!
原来是因为 xxx.dll.refresh 文件处于签出状态,可以更改造成的!!!!!!那个寒啊!!!!!!!!!