在Global.asax

时间:2017-10-25 20:22:07

标签: c# asp.net asp.net-mvc iis

这在本地和我们的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()设置。

到目前为止我尝试过:

  1. 我的ASP.NET网站已预先编译,因此我确认PrecompiledApp.config位于我网站的根目录中
  2. 我确认bin目录中存在App_global.asax.dllApp_global.asax.compiledApp_global.asax.pdb
  3. 我确认应用程序池正在以经典模式运行
  4. 我清除了临时ASP.net文件
  5. 我的网站的IIS应用程序池具有以下属性:

    1. NET CLR版本:v4.0
    2. 启用32位应用程序= true
    3. 托管管道模式=经典
    4. 启动模式= OnDemand
    5. 我很肯定这台服务器上有某种配置会导致Application_Start()无法启动,但我不确定它是什么。

      我已经阅读并尝试了下面建议的方法,但到目前为止没有运气:

      1. Global.asax not loading for precompiled asp.net website
      2. Application_Start is not being called in IIS
      3. Application_Start is not firing in IIS
      4. 这让我发疯了。请帮忙。谢谢!

        编辑:根据您的要求,这是我的整个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文件。

1 个答案:

答案 0 :(得分:0)

这是一个Windows问题!安装最新的Windows Server 2012 R2更新后,此问题不再发生!