【发布时间】:2017-10-25 20:22:06
【问题描述】:
这在本地和我们的 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_Start() 永远不会设置此 Application["ApplicationName"]。
到目前为止我所尝试的:
- 我的ASP.NET网站是预编译的,所以我验证
PrecompiledApp.config在我网站的根目录下 - 我验证了
App_global.asax.dll、App_global.asax.compiled和App_global.asax.pdb存在于 bin 目录中。 - 我已验证应用程序池在经典模式下运行
- 我清除了临时 ASP.net 文件
我网站的 IIS 应用程序池具有以下属性:
- NET CLR 版本:v4.0
- 启用 32 位应用程序 = true
- 托管管道模式 = 经典
- 启动模式 = 按需
我确信此服务器上存在某种配置导致 Application_Start() 无法触发,但我不确定它是什么。
我已经阅读并尝试了以下建议的方法,但到目前为止没有运气:
- Global.asax not loading for precompiled asp.net website
- Application_Start is not being called in IIS
- Application_Start is not firing in IIS
这让我发疯了。请帮忙。谢谢!
编辑:根据您的要求,这是我的整个 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 文件。
【问题讨论】:
-
您可以访问应用程序内的页面吗?
-
@mason 是的,这些页面是可访问的,但我的调度程序线程永远不会产生,因为 Application["ApplicationName"] 不是由 Application_Start 设置的。
-
您记录的事件永远不会被记录? global.asax 中的其他方法呢?
-
如果您在事件日志中没有找到任何内容,请确保您的事件日志设置正确并且具有写入权限。它可能会默默地在第一行失败。
-
@mason 没有从该客户端服务器中的 global.asax 记录任何内容。在我们的 QA 服务器中,它运行良好,我们可以看到日志。
标签: c# asp.net asp.net-mvc iis