Codefile directive validity with @Application ?

W

WT

Hello,
In my Global.asax file, I have only an @ Application directive like
<%@ Application Language="C#" Inherits="WT.Global" CodeFile="Global.asax.cs"
%>



Visual studio complains saying that CodeFile is no valid for Application but
the documentation says to use it for Codebehind ?

What to do ?

CS
 
S

Swanand Mokashi

S

Steven Cheng[MSFT]

Hi CS,

As for the ASP.NET application you're concering on, is it an ASP.NET 2.0
application developed in VS 2005? If so, vs 2005 by default do not use
codebehind for global.asax component. Also, if you want to use codebehind
class for the global.asax's application class, you can manually create a
class file which contains the global class and put it in the App_Code
directory. e.g:

====in global.asax=========
<%@ Application Language="C#" CodeBehind="MyGlobal.cs" Inherits="MyGlobal"
%>

then, in App_Code dir, we should contains a

MyGlobal.cs file which define the "MyGlobal" class like:

public class MyGlobal : HttpApplication
{


Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

WT

Hi Steven,

Thanks again. Your information concerning CodeBehind="MyGlobal.cs" is not
inthe vs2005 documentation, it only mention CodeFile for @Application, or I
should update my VS doc ?

CS

PS: I have still my publish problem: compiler aspnet_compiler.exe stops on a
class with any comment, even in diagnostic mode ???
 
S

Steven Cheng[MSFT]

Thanks for your quick response CS,

Sorry for my carelessness, after some further research, I think the MSDN
document on the @ Application directive is correct:

#@ Application - Global.asax
http://msdn2.microsoft.com/en-us/library/es4ac4ek.aspx

So for using custom global class file for globa.asax file in ASP.NET 2.0
appliation, we have the following two options:

1. Just use the "Inherits" attribute to specify a base class , and this
class can exist in either a source file in App_Code dir or in a referenced
class library assembly. Just like the one in my last message, and the
"codebehind" attribute is optional, which is for compatibility to vs 2003
style codebehind.

2. If we want to use ASP.NET 2.0 style partial class codebeind file for
global.asax, we can just add a codebehind file which contains the partial
class, and then reference the partial class and codefile in @Application
directive, e.g:

#Note that the MyGlobal.cs file here is not put in App_Code, just put side
by side with global.asax file and will be dynamically compiled:

==========global.asax========
<%@ Application Language="C#" CodeFile="MyGlobal.cs" Inherits="MyGlobal"
%>


=======in MyGlobal.cs=========
public partial class MyGlobal : HttpApplication
{
...............

}

=====================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top