Global.asax.cs events do not fire after publishing a website

I searched the Internet for hours on this, so I hope someone here can help.

I have WebSite in VS 2010 (.Net 4.0 framework, C #) that has a Global.asax file in the root directory and a Global.asax.cs file in the App_Code folder. (Note that this is a WebSite, not a web application.) When I run this WebSite from my local development machine, everything works as expected - more specifically, the Session_Start event in the Global.asax.cs file fires and runs some code at the beginning of each session to get login credentials that determine that they are allowed View / edit in the application based on their security level.

However, as soon as I publish this WebSite on a Windows 2003 R2 server, none of the events in the Global.asax.cs file are fired. (Only the Session_Start event needs code, but I also add code to Application_Start, just to see if it lights up - it's not).

Here is the Global.asax code:

<%@ Application CodeBehind="~\App_Code\Global.asax.cs" Inherits="Global" Language="C#" %>

Here is the Global.asax.cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Global
/// </summary>
public partial class Global : System.Web.HttpApplication
{

    public Global()
    {

    // TODO: Add constructor logic here

    }

    protected void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
    }

    protected void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
    }

    protected void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        try
        {
            Session["SessionSink"] = new SessionSink();             
            this.GetUserName();                              
        }
        catch (Exception ex)
        {
            string msg = "An error occurred in Global.asax::Session_Start";
            ExceptionWriter ew = new ExceptionWriter();
            ew.LogError(msg, ex);
        }
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 

    }
}

Some notes based on other answers / discussions I read: After publishing, PrecompiledApp.config appears in the website folder. In addition, App_global.asax.compiled and App_global.asax.dll are displayed in the bin folder.

Does anyone know what the problem is? Why does this work from my local machine, but not after publishing it to the server? Is there an IIS setting that I am missing?

This is my first time using asp.net, so any help would be greatly appreciated. Thank.

+5
1

, global.asax.cs; .. global.asax.cs global.asax

<%@ Application Language="C#" Inherits="System.Web.HttpApplication" %>
<script runat="server">
  public override void Init() {
    base.Init();
    var module = (SessionStateModule)Modules["Session"];
    module.Start += new EventHandler((sender, args) => {
        // create session sink here
    });
  }
</script>
0

All Articles