Solved

global.asax not working in ASP.NET 2.0

Posted on 2009-06-30
3
926 Views
Last Modified: 2013-11-07
Last night we upgraded from ASP.NET 1.1 to ASP.NET 2.0.  I have noticed that our Application_Error handler is not firing from Global.asax.

In visual studio we have a class, Epic.Web.Global.  See source code below.  The Application_Error is not firing but instead a log is written to the windows event log regarding the unhandled exception.

We used VS 2008 to upgrade our project from VS 2003 but the actual Global.asax file has never been part of our VS project file -- it's just a file we dropped on IIS in the application root directory.  The compiled Epic.Web.DLL file is dropped in application root\bin directory.

I have since tried adding a new Global.asax file to the VS project but then it wants to do a code behind file and drop the .cs file in App_Code.  I don't want to do that -- I want to use our DLL using inherits in Global.asax but I haven't figured out how to make it work.

This worked fine in .NET 1.1 and should be simple but I haven't found the quirk yet.  I have found articles on here and on google regarding people with similiar problems but haven't found an answer that works for us.  There was something regarding PrecompiledApp.config but it's not a file we have.  We have web.config and it does have custom errors turned on.


Thanks

Our Global.asax file:
 
<%@ Application Language="C#" Inherits="Epic.Web.Global" %>
 
Our Global.cs file:
 
namespace Epic.Web
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Error(object o, EventArgs e)
        {
          Exception exception = Server.GetLastError();
          // do work
         Server.ClearError(); // tried with and without this
        }
    }
}

Open in new window

0
Comment
Question by:DJE-
  • 2
3 Comments
 
LVL 3

Expert Comment

by:tpsl
ID: 24751519
As far as I know with asp.net 2.0 you need to place all .cs files in app_code...

which is why it is asking you to place it in that folder. Otherwise you won't be able to access that file.

Why don't u want it in app_code folder?

0
 

Author Comment

by:DJE-
ID: 24753779
I don't want source code on a production server -- not good practice.

We pre-compile everything and in the past (.NET 1.1) there was no problem placing Epic.Web.DLL (our precompiled DLL file) in the bin folder and using "Inherits" in the asax file.
0
 

Accepted Solution

by:
DJE- earned 0 total points
ID: 24764311
It turns out our Application_Error method itself was throwing another exception, causing it to not behave as expected.  Some of our "// do work" code within Application_Error did not run the same in 3.5 as it did under 1.1 (without error).  So you can still use Inherits in Global.asax with all of the source precompiled in a .DLL file, good!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question