簡體   English   中英

在Global.asax中未觸發Application_Start()

[英]Application_Start() is not getting fired in Global.asax

這在本地以及我們的質量檢查服務器中都可以正常工作。 但是,在我們的一台客戶端服務器中,看來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”]。

到目前為止我嘗試過的是:

  1. 我的ASP.NET網站是預編譯的,因此我驗證了PrecompiledApp.config在我的網站的根目錄中
  2. 我驗證了bin目錄中存在App_global.asax.dllApp_global.asax.compiledApp_global.asax.pdb
  3. 我驗證了應用程序池正在經典模式下運行
  4. 我清除了臨時的ASP.net文件

我的網站的IIS應用程序池具有以下屬性:

  1. NET CLR版本:v4.0
  2. 啟用32位應用程序= true
  3. 托管管道模式=經典
  4. 啟動模式=按需

我很肯定該服務器上存在某種配置,該配置導致Application_Start()無法啟動,但是我不確定它是什么。

我已經閱讀並嘗試了以下建議的方法,但到目前為止還沒有運氣:

  1. Global.asax無法為預編譯的asp.net網站加載
  2. IIS中未調用Application_Start
  3. 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文件。

這是Windows問題! 安裝最新的Windows Server 2012 R2更新后,此問題不再發生!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM