这在本地和我们的QA服务器中都可以正常工作。但是,在我们的一个客户端服务器中,似乎根本没有触发Application_Start()。
我的Application_Start()如下所示:
void Application_Start(object sender, EventArgs e)
{
EventLogging.LogEvent("Application_Start() fired in Global.asax.", EventLogging.LogLevel.Basic);
Application["ApplicationName"] = "My Application Name";
EventLogging.LogVerbose("Application_Start() - ApplicationName: " + (Application["ApplicationName"] ?? "NA"));
}
在我的一个代码模块中,我检查Application [" ApplicationName"],如果它有值,我启动一个长期运行的调度程序线程。问题是这个Application [" ApplicationName"]永远不会被Application_Start()设置。
到目前为止我尝试过:
PrecompiledApp.config
位于我网站的根目录中App_global.asax.dll
,App_global.asax.compiled
和App_global.asax.pdb
。我的网站的IIS应用程序池具有以下属性:
我很肯定这台服务器上有某种配置会导致Application_Start()
无法启动,但我不确定它是什么。
我已经阅读并尝试了下面建议的方法,但到目前为止没有运气:
这让我发疯了。请帮忙。谢谢!
编辑:根据您的要求,这是我的整个global.asax:
<%@ Application Language="C#" Inherits="WebFramework.GlobalBase" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Http" %>
<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Reflection" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
EventLogging.LogEvent("Application_Start() fired in Global.asax.", EventLogging.LogLevel.Basic);
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Application["ApplicationName"] = "My Application";
EventLogging.LogVerbose("Application_Start() - ApplicationName: " + (Application["ApplicationName"] ?? "NA"));
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.ToLower() == "sessionid")
{
return context.Session.SessionID;
}
return base.GetVaryByCustomString(context, custom);
}
</script>
注意:GlobalBase.cs基本上是一个什么都不做的cs文件。
答案 0 :(得分:0)
这是一个Windows问题!安装最新的Windows Server 2012 R2更新后,此问题不再发生!