Application_Start 在 ASP.Net 4.0 应用程序中行为不正确
我很困惑。我浏览了 StackOverflow 和 Google 上的所有建议……没有什么乐趣。
我的 Application_Start 方法在 ASP.Net 4.0 应用程序中运行不正确。我可以设置应用程序变量,但不能调用我的日志记录方法。
我可以设置变量:
Application["appStartDT"] = DateTime.Now.ToString();
但是我的日志记录方法没有被调用:
Utilities.writeLog("Application started at: " + System.DateTime.Now.ToString(), 4);
这发生在我从 VWDE 2010 中的内部 IIS 服务器切换到 IIS 7.5(在 Windows 7 上)时,尽管我不是 100% 它相关(必须切换) ,因为我使用的是虚拟目录)。
[后脚本编辑:我将项目切换回“使用 Visual Studio 开发服务器”,并且我的 Application_Start 方法触发并执行了我的日志记录方法。我需要使用 IIS。关于我忽略的 IIS 设置有什么建议吗?]
任何建议都会有帮助。
尊敬的
雷
I'm stumped. I ran through all the recommendations on StackOverflow and Google... no joy.
My Application_Start method is not behaving correctly in my ASP.Net 4.0 application. I can set Application variables, but not call my logging method.
I can set variables:
Application["appStartDT"] = DateTime.Now.ToString();
But my logging method is not called:
Utilities.writeLog("Application started at: " + System.DateTime.Now.ToString(), 4);
This happened about the time I switched from the internal IIS server in VWDE 2010 to IIS 7.5 (On Windows 7), though I'm not 100% it's related (had to switch, as I was using virtual directories).
[Post Script Edit: I switched to project back to "Use Visual Studio Development Server" and my Application_Start method fired and executed my logging method. I need to use IIS. Any suggestion on what IIS setting I am overlooking?]
Any suggestions would be helpful.
Respectfully,
Ray
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为切换到 IIS 的一个区别是,您的网站正在运行的 IIS 进程现在将是 [本地计算机]\网络服务帐户。我假设您的 Utilities.writeLog 方法正在将某些内容写入文件。如果确实如此,那么您应该检查网络服务帐户是否对您正在记录的文件和文件夹具有读/写权限。我在 log4Net 将输出记录到文件时遇到了同样的问题,当我向网络服务帐户授予对我正在记录的文件夹/文件的访问权限时,问题就消失了。
I think one difference with switching to IIS is that the IIS process that your website is running under will now be the [local machine]\Network Service account. I am assuming that your
Utilities.writeLog
method is writing something out to a file. If that in fact is the case, then you should check that the Network Service account has read/write privileges to the file and folder where you are logging. I have experienced this same issue with log4Net logging output to a file and when I gave the Network Service account access to the folder/file I was logging to, the issue went away.