Welcome to AspAdvice Sign in | Join | Help

asp.net 2.0 - Global.asax - Code Behind file - MSDN documentation

MSDN documentation appears to be wrong on code behind file for Global.asax.  Documentation here says that

CodeFile

Specifies a path to the referenced code-behind file for the application class. This attribute is used together with the Inherits attribute to associate a code-behind source file with an application file.

However in VisualStudio.Net 2005 Global.asax won't allow you to have a 'CodeFile' attribute!  If you try to add a partial class and try to specify it as the CodeFile attribute value, IDE throws the followin g compiler error.

Validation (ASP.Net): Attribute 'CodeFile' is not a valid attribute of element 'Application'.

It appears that only way to have a global.asax.cs is to place that file in the App_Code directory and in the global.asax file just specify the Inherits attribute pointing to that class defined in the global.asax.cs.

Global.asax.cs in the app_code folder:

public class YourGlobalClass : HttpApplication
{
}

Global.asax file:
<%@ Application Language="C#" Inherits="YourGlobalClass" %>

Sponsor
Published Sunday, December 11, 2005 11:35 PM by kiran chand

Comments

# http://configurationmanagement-strategy.com/

Sunday, July 30, 2006 11:33 AM by TrackBack

# cthrall.com &raquo; Blog Archive &raquo; Code File for Global.asax

Wednesday, March 26, 2008 8:40 AM by cthrall.com » Blog Archive » Code File for Global.asax

# How to: Hidden Features of ASP.NET | SevenNet

Wednesday, November 26, 2014 5:15 PM by How to: Hidden Features of ASP.NET | SevenNet

# Solution: Hidden Features of ASP.NET #dev #it #computers | Technical information for you

# Fixed Hidden Features of ASP.NET #dev #it #asnwer | Good Answer

Anonymous comments are disabled