473,721 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What happened to the Global class code behing in 2.0?

Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
Jul 16 '07 #1
15 2569
It's not the default any more, but you can still use it.

Read this article :
http://www.xerratus.com/2006/10/20/N...arateFile.aspx

You need to place all your global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.Http Application

....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Glo bal.asax.cs" Inherits="Globa l" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Glo bal.asax.vb" Inherits="Globa l" %>

Download a complete example from :

http://www.xerratus.com/ct.ashx?id=c...iteExample.zip

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========

"PatB" <Pa**@community .nospamwrote in message news:45******** *************** ***********@mic rosoft.com...
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY

Jul 16 '07 #2
Please never assume anything and ALWAYS post the exact behavior you see
(runtime error, compile time error, exact error message).
Of course if we try, it will work as we are not in the same condition (my
guess would be a namespace change ?)

My personal preference would be to use a specific class (also the
configuration class provides an API that will expose values stored in your
web application config class, see WebConfiguratio nManager).

--
Patrice

"PatB" <Pa**@community .nospama écrit dans le message de news:
45************* *************** **...icrosof t.com...
Just starting to move to ASP.NET 2.0 and having trouble with the
Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This
allow
for shared variables of the Global class. Note: I use these shared
variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY

Jul 16 '07 #3
Juan,

I implemented the work-around and it appears to be working.

In my 1.1 code I can reference these shared variables by
Global.Variable Name. In the 2.0 code it appears that I need to reference
then with two global references like this: Global.Global.V ariableName.

Should it be like this? Is something wrong? This will mean when converting
my 1.1. apps I'll have to make a lot of changes to change the Global.
reference to Global.Global.

Does anyone know the reasoning why Microsoft removed the code behind model
for the global.asax?
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
"Juan T. Llibre" wrote:
It's not the default any more, but you can still use it.

Read this article :
http://www.xerratus.com/2006/10/20/N...arateFile.aspx

You need to place all your global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.Http Application

....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Glo bal.asax.cs" Inherits="Globa l" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Glo bal.asax.vb" Inherits="Globa l" %>

Download a complete example from :

http://www.xerratus.com/ct.ashx?id=c...iteExample.zip

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========

"PatB" <Pa**@community .nospamwrote in message news:45******** *************** ***********@mic rosoft.com...
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY


Jul 16 '07 #4
there is no need for a codebehind file. you just put the code in
global.asax file. as there is nothing but the code in the global.asax
file, 2 files don't make much sense.

-- bruce (sqlwork.com)


PatB wrote:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).

Jul 16 '07 #5
If you're "just starting" to move into ASP.NET 2.0, then it's not too late to
start developing good habits. One that I've gotten is NOT to use the Web Site
Project model, but the Web Application Project model for building my "stuff".
The original global.asax codebehind arrangement is preserved. My humble
opinion, of course.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder( BETA): http://www.blogmetafinder.com

"PatB" wrote:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
Jul 16 '07 #6
re:
!I implemented the work-around and it appears to be working.

Yes, it does work.

re:
!In the 2.0 code it appears that I need to reference
!then with two global references like this: Global.Global.V ariableName.

!Should it be like this?

I can only suggest for you to look for a Global subclassing of Global in your code.
Experiment...an d remove one of the Global subclassings.

re:
!Does anyone know the reasoning why Microsoft removed the code behind model for the global.asax?

Because it's wasted effort.
You don't need to compile the codebehind first, and then compile the global.asax class again at runtime.

Anything you can do in codebehind you can also do inline, so the codebehind isn't needed.
You can still implement it, like I pointed out, but, really, you're only duplicating compilation efforts.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
"PatB" <Pa**@community .nospamwrote in message news:18******** *************** ***********@mic rosoft.com...
Juan,

I implemented the work-around and it appears to be working.

In my 1.1 code I can reference these shared variables by
Global.Variable Name. In the 2.0 code it appears that I need to reference
then with two global references like this: Global.Global.V ariableName.

Should it be like this? Is something wrong? This will mean when converting
my 1.1. apps I'll have to make a lot of changes to change the Global.
reference to Global.Global.

Does anyone know the reasoning why Microsoft removed the code behind model
for the global.asax?
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
"Juan T. Llibre" wrote:
>It's not the default any more, but you can still use it.

Read this article :
http://www.xerratus.com/2006/10/20/N...arateFile.aspx

You need to place all your global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.Http Application

....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Glo bal.asax.cs" Inherits="Globa l" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Glo bal.asax.vb" Inherits="Globa l" %>

Download a complete example from :

http://www.xerratus.com/ct.ashx?id=c...iteExample.zip

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
============== =============== =========

"PatB" <Pa**@community .nospamwrote in message news:45******** *************** ***********@mic rosoft.com...
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY



Jul 16 '07 #7
Bruce,

Try to add a shared variable? You can't do it without a code behind file
with a class definition. At least I couldn't get it to do it.

--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
"bruce barker" wrote:
there is no need for a codebehind file. you just put the code in
global.asax file. as there is nothing but the code in the global.asax
file, 2 files don't make much sense.

-- bruce (sqlwork.com)


PatB wrote:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
Jul 16 '07 #8
Ah, my turn to say to you : good point, Peter.
WAP can work that way.

I still prefer inline code, though. I use it when building WAP apps.

;-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .comwrote in message
news:2E******** *************** ***********@mic rosoft.com...
If you're "just starting" to move into ASP.NET 2.0, then it's not too late to
start developing good habits. One that I've gotten is NOT to use the Web Site
Project model, but the Web Application Project model for building my "stuff".
The original global.asax codebehind arrangement is preserved. My humble
opinion, of course.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder( BETA): http://www.blogmetafinder.com

"PatB" wrote:
>Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY

Jul 16 '07 #9
Peter,

I created a ASP.NET AJAX-enabled Web application.

Your comments confuse me. What's the difference between Web Site Project
model amd the Web Application Project model? How do I switch or create a Web
Application Project Model? Am I missing something during the project creation?

Thank you,

--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
"Peter Bromberg [C# MVP]" wrote:
If you're "just starting" to move into ASP.NET 2.0, then it's not too late to
start developing good habits. One that I've gotten is NOT to use the Web Site
Project model, but the Web Application Project model for building my "stuff".
The original global.asax codebehind arrangement is preserved. My humble
opinion, of course.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder( BETA): http://www.blogmetafinder.com

"PatB" wrote:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn't like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A BÖWE BELL + HOWELL COMPANY
Jul 16 '07 #10

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

Similar topics

220
19078
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
121
10111
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
17
5625
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
4
2424
by: Leo Muller | last post by:
I am about to deploy my first ASP.NET project. But, I was used to store my variables, such as connection strings, in the global.asa file, in an application. However, these variables are different on my development and production server. If I use the global.asax file, then it is in the code behing, compiled part. Thus I can't change the setting on my production server. So where is the right place to save my connecting string? Leo
22
3790
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to manipulate them. It starts > and ends with <script></script> tags. > > Yours looks like a compiled version of it.
4
2368
by: Chris | last post by:
Hi, I want to put the namespaces and the data connection into global.asax like this: <%@ import namespace="System.Data"%> <%@ import namespace="System.Data.OleDb"%> <script runat="server"> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Dim oConnection As System.Data.OleDb.OleDbConnection oConnection = New System.Data.OleDb.OleDbConnection()
12
8643
by: =?Utf-8?B?QnJhZA==?= | last post by:
i dont understand this behaviour... i open a vb form i created and want to save it as a new name and make some changes when i do (in vs2005) the original form looses its ui whats up with that??? it turned into a straight class
4
1678
by: lightaiyee | last post by:
Dear Gurus, I would like to implement a function that computes the number of times a certain condition is met in a global array. For example, I have an global array of size 500. float array; I have a function that finds the maximum of an array of size 50. bool findMax50(float input)
8
1532
by: Viktor | last post by:
Can somebody give me an explanation what happened here (or point me to some docs)? Code: HMMM = None def w(fn): print 'fn:', id(fn) HMMM = fn
0
8840
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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

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.