Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global.asax not loading for precompiled asp.net website

I used Visual Studio 2008 to publish my asp.net website. When I bring up the website on the server (Windows 2008 server), I noticed that the code in global.asax was not running. My Global.asax body is similar to:

<%@ Application Language="C#" %>
<script runat="server">
    protected void Application_Start()
    {
        // Initialize some site settings like a task scheduler
    }

    protected void Application_End(object sender, EventArgs e)
    {
        // Perform some clean up code
    }
</script>

There is a App_global.asax.dll in the compiled websites bin folder, but that does not seem to help.

Is there a configuration option that I'm missing? Removing the App_global.asax.dll and using the original global.asax with the precompiled website works fine.

like image 591
Jim Geurts Avatar asked Oct 27 '09 18:10

Jim Geurts


People also ask

Can we run ASP.NET application without global asax file?

asax is not required by ASP.NET for a website to run. It is, however, very useful for application-level functionality (like unhandled exception logging). Save this answer.

How do I add global asax Cs to my website?

How to add global. asax file: Select Website >>Add New Item (or Project >> Add New Item if you're using the Visual Studio web project model) and choose the Global Application Class template. After you have added the global.

What is Application_Start in global asax?

The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.


2 Answers

The only answer I've found is to include global.asax (with logic) in the compiled output folder.

like image 85
Jim Geurts Avatar answered Oct 07 '22 06:10

Jim Geurts


I had a similar problem and managed to resolve it by removing the PrecompiledApp.config file from the website's root folder on our development server.

I think that this may have been transferred to the server when publishing from Visual Studio.

like image 39
Jonathan Williams Avatar answered Oct 07 '22 05:10

Jonathan Williams