473,559 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change Global.asax to code-behind

ad
The Global.asax is code-inside with default.
How to change Global.asax to code-behind?
Nov 19 '05 #1
5 15012
In global.asax you need to modify the @ Application directive.

<%@ Application
Codebehind="Glo bal.asax.cs" Inherits="YourN amespace.Global " %>

Then create your .asax.cs file, and add a class named Global derived
from System.Web.Http Application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 21:17:22 +0800, "ad" <fl****@wfes.tc c.edu.tw>
wrote:
The Global.asax is code-inside with default.
How to change Global.asax to code-behind?


Nov 19 '05 #2
AFAIK, that's gone from ASP.NET/VS.NET 2.0, though.

The new Web project model affects the Global.asax file.

In 2.0, when you convert a previous project :

1. the global.asax code-behind file's contents are moved to the App_Code directory.

2. The CodeBehind and Inherits attributes are removed from the @ Page directive.

3. A Language attribute is added to the @ Page directive, if one is not already specified.

4. For Visual Basic, a Namespace statement is added to the class file.
The namespace is defined by the root namespace in the Web project.

VS.NET 2005 won't even let you create a global.asax
with a code-behind file in any new website you create.

See : http://msdn2.microsoft.com/en-us/lib...us,vs.80).aspx

The section titled "Global.asa x File"


Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
=============== ===========

"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:2f******** *************** *********@4ax.c om...
In global.asax you need to modify the @ Application directive.

<%@ Application
Codebehind="Glo bal.asax.cs" Inherits="YourN amespace.Global " %>

Then create your .asax.cs file, and add a class named Global derived
from System.Web.Http Application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 21:17:22 +0800, "ad" <fl****@wfes.tc c.edu.tw>
wrote:
The Global.asax is code-inside with default.
How to change Global.asax to code-behind?


Nov 19 '05 #3
That's an odd piece of documentation you found, Juan. I'm not sure why
global.asax would ever have an @ Page directive.

I know VS2005 doesn't let you create a global.asax with a code-behind
file, but adding the CodeBehind and Inherits attributes and putting
the .cs file in App_Code does work - I've tried it. There is not much
of a benefit in doing so, though.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 11:06:33 -0400, "Juan T. Llibre"
<no***********@ nowhere.com> wrote:
AFAIK, that's gone from ASP.NET/VS.NET 2.0, though.

The new Web project model affects the Global.asax file.

In 2.0, when you convert a previous project :

1. the global.asax code-behind file's contents are moved to the App_Code directory.

2. The CodeBehind and Inherits attributes are removed from the @ Page directive.

3. A Language attribute is added to the @ Page directive, if one is not already specified.

4. For Visual Basic, a Namespace statement is added to the class file.
The namespace is defined by the root namespace in the Web project.

VS.NET 2005 won't even let you create a global.asax
with a code-behind file in any new website you create.

See : http://msdn2.microsoft.com/en-us/lib...us,vs.80).aspx

The section titled "Global.asa x File"


Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
============== ============

"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:2f******* *************** **********@4ax. com...
In global.asax you need to modify the @ Application directive.

<%@ Application
Codebehind="Glo bal.asax.cs" Inherits="YourN amespace.Global " %>

Then create your .asax.cs file, and add a class named Global derived
from System.Web.Http Application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 21:17:22 +0800, "ad" <fl****@wfes.tc c.edu.tw>
wrote:
The Global.asax is code-inside with default.
How to change Global.asax to code-behind?



Nov 19 '05 #4
re:
I'm not sure why global.asax would ever have an @ Page directive.
The doc refers to the changes made by project *conversions*.
As usual with MS documentation, you need to interpret it. ;-)

re: adding the CodeBehind and Inherits attributes
and putting the .cs file in App_Code does work
Yup, but the explanation is nowhere to be found,
*except in that document*.

I, also, hate the idea of putting source code on a server.

I don't know who came up with that doozy, but they should
be hung by their you-know-whats for inflicting that on us.

I'm skipping that part entirely by manually compiling to assemblies
anything which would go into App_Code as raw code.

I see the App_Code directory as a security failpoint.

I'm not sure if there's any advantage any more to using
codebehind, anyway, particularly with global.asax.

If you can do anything with inline coding, or manually-compiled assemblies,
that you can do with codebehind, why should we have to go through the
additional contortions which codebehind requires ?

Do you know of anything which can be done in codebehind
which can't be done inline or with command-line compiled assemblies ?

I'm finding the codebehind model a bit hard to swallow these days
primarily because of the additional complexity which it requires,
and the usual explanation that it "separates UI from code" sounds,
increasingly, hollow.

I can separate UI from code with manually-compiled assemblies.

Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
=============== ===========

"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:7m******** *************** *********@4ax.c om... That's an odd piece of documentation you found, Juan. I'm not sure why
global.asax would ever have an @ Page directive.

I know VS2005 doesn't let you create a global.asax with a code-behind
file, but adding the CodeBehind and Inherits attributes and putting
the .cs file in App_Code does work - I've tried it. There is not much
of a benefit in doing so, though.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 11:06:33 -0400, "Juan T. Llibre"
<no***********@ nowhere.com> wrote:
AFAIK, that's gone from ASP.NET/VS.NET 2.0, though.

The new Web project model affects the Global.asax file.

In 2.0, when you convert a previous project :

1. the global.asax code-behind file's contents are moved to the App_Code directory.

2. The CodeBehind and Inherits attributes are removed from the @ Page directive.

3. A Language attribute is added to the @ Page directive, if one is not already
specified.

4. For Visual Basic, a Namespace statement is added to the class file.
The namespace is defined by the root namespace in the Web project.

VS.NET 2005 won't even let you create a global.asax
with a code-behind file in any new website you create.

See : http://msdn2.microsoft.com/en-us/lib...us,vs.80).aspx

The section titled "Global.asa x File"


Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
============= =============

"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:2f****** *************** ***********@4ax .com...
In global.asax you need to modify the @ Application directive.

<%@ Application
Codebehind="Glo bal.asax.cs" Inherits="YourN amespace.Global " %>

Then create your .asax.cs file, and add a class named Global derived
from System.Web.Http Application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 21:17:22 +0800, "ad" <fl****@wfes.tc c.edu.tw>
wrote:

The Global.asax is code-inside with default.
How to change Global.asax to code-behind?


Nov 19 '05 #5
On Sat, 10 Sep 2005 21:39:56 -0400, "Juan T. Llibre"
<no***********@ nowhere.com> wrote:

If you can do anything with inline coding, or manually-compiled assemblies,
that you can do with codebehind, why should we have to go through the
additional contortions which codebehind requires ?

Do you know of anything which can be done in codebehind
which can't be done inline or with command-line compiled assemblies ?


I can't think of anything you can or can't do in one model that you
can do in the other.

I was sticking with code-behind based on the close-minded principal
that it was "the right way to do it".

The more I learned abouyt 2.0 the more I started liking inline code -
it's one less file to manage, one less file to "diff" ... etc. There
is no difference in productivity or tool support in 2.0!

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3804
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it (the oleDBConnection on global.asa.vb) at the other aspx pages ?
2
5194
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb file, and what would I do to access it? (I am using VB.NET for my code) Thanks. -- Nathan Sokalski njsokalski@hotmail.com...
8
4853
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web...
4
7611
by: John A Grandy | last post by:
I installed VS05 RC , created a new Web Site , but I do not see Global.asax , and I do not see Global.asax.cs in the App_Code dir ......
0
2443
by: hynek.cihlar | last post by:
A strange behaviour thatI found in ASP.NET 2.0. I am trying to issue a callback request (handled by ICallbackEventHandler and RaiseCallbackEvent) and a regular GET request in the client browser and handle them at the same time - in parallel. The funny thing is that the behaviour of the implementation I created depends on the existence of...
1
3274
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are probably more common than HttpHandlers, but could still stand to be advertised a bit more. HttpModules are incredibly easy to explain, so this will...
1
1464
by: GaryDean | last post by:
I notice that the global.asax in v2 is inline. because of this I can't say Session = conn; The compiler will accept it but at runtime the exception says "Session State is not available in this context". Is this a downgrade feature from 1.1? -- Regards,
4
3025
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the debugger unless I add a Global.asax file. When I do that and then try to run the debugger I receive error 403. If I remove the Global.asax file...
16
5018
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="<Namespace>." %> I've done a lot of things I've found on the web to no avial, but here are some...
3
5245
by: Peter Larsen [CPH] | last post by:
Hi, I have a problem where the code in Global.asax.cs runs before the unittests (on test of course). In the global file, i load some data from a Oracle table and save it in HttpApplicationState. This is happening in the Application_start function. The following unittest show the beginning of the method, where the database mock is...
0
7629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7836
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5455
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
872
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.