473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

No access to Global.asax methods in ASP.Net 2.0

I've created a simple web application using VS2005 Beta 2.

Basically, I've added a Web Form and a Global.asax file.

In my Global.asax, I create a method like:

public static void TestGlobal() {
throw new Exception("Foobar");
}

The problem, however, is that I cannot gain access to this method from the
form class, i.e., this code fails:

protected void Page_Load(object sender, EventArgs e) {
Global.TestGlobal(); // Intellisense claims no class Global exist.
}

You would write like this in ASP.Net 1.1, but how would you access methods,
enums, etc in Global.asax in ASP.Net 2.0?

Ronnie
Nov 19 '05 #1
10 3006
If the code's all in the ASAX (instead of a ASAX codebehind), try:

Global_asax.TestGlobal();

-Brock
DevelopMentor
http://staff.develop.com/ballen
I've created a simple web application using VS2005 Beta 2.

Basically, I've added a Web Form and a Global.asax file.

In my Global.asax, I create a method like:

public static void TestGlobal() {
throw new Exception("Foobar");
}
The problem, however, is that I cannot gain access to this method from
the form class, i.e., this code fails:

protected void Page_Load(object sender, EventArgs e) {
Global.TestGlobal(); // Intellisense claims no class Global exist.
}
You would write like this in ASP.Net 1.1, but how would you access
methods, enums, etc in Global.asax in ASP.Net 2.0?

Ronnie


Nov 19 '05 #2
Global_asax isn't a valid namespace either, so that doesn't work.

Ronnie

Brock Allen wrote:
If the code's all in the ASAX (instead of a ASAX codebehind), try:

Global_asax.TestGlobal();

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #3
It's not a namespace, it's the name of the class generated from the global.asax.
I just tested it locally and it was functional. I'm wondering what might
be different....

-Brock
DevelopMentor
http://staff.develop.com/ballen
Global_asax isn't a valid namespace either, so that doesn't work.

Ronnie

Brock Allen wrote:
If the code's all in the ASAX (instead of a ASAX codebehind), try:

Global_asax.TestGlobal();

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #4
Ah, I bet you're trying it from codebehind? My tests were all from codeinside
in my ASPX.

So, you can build a codebehind for your global.asax like the "olden days"
:). Make a class in the App_Code folder called "Global" that inherits HttpApplication.
In your global.asax add an Inherits="Global" directove. Then your codebehind
classes can see/use the Global class in App_Code.

Now having done all of that, I'm not sure why putting code there is any different
or any more useful than simply putting that code into its own class (not
global.asax related) in App_Code. What's your motivation for making that
code in global.asax (I've lost the original post)?

-Brock
DevelopMentor
http://staff.develop.com/ballen
It's not a namespace, it's the name of the class generated from the
global.asax. I just tested it locally and it was functional. I'm
wondering what might be different....

-Brock
DevelopMentor
http://staff.develop.com/ballen
Global_asax isn't a valid namespace either, so that doesn't work.

Ronnie

Brock Allen wrote:
If the code's all in the ASAX (instead of a ASAX codebehind), try:

Global_asax.TestGlobal();

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #5
Why would you want to access methods which
*already* are run automatically in global.asax ?

If you want to throw an exception in a page, use :

<script runat="server">
void Error_Click(Object sender, EventArgs e) {
throw new Exception();
}
</script>

And, in the body, include :

<input type="submit" OnServerClick="Error_Click" Value="Generate An Error"
runat="server"/>


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Ronnie" <r_******@yahoo.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
I've created a simple web application using VS2005 Beta 2.

Basically, I've added a Web Form and a Global.asax file.

In my Global.asax, I create a method like:

public static void TestGlobal() {
throw new Exception("Foobar");
}

The problem, however, is that I cannot gain access to this method from the
form class, i.e., this code fails:

protected void Page_Load(object sender, EventArgs e) {
Global.TestGlobal(); // Intellisense claims no class Global exist.
}

You would write like this in ASP.Net 1.1, but how would you access methods,
enums, etc in Global.asax in ASP.Net 2.0?

Ronnie

Nov 19 '05 #6
You're right. If you create a code behind Global.asax.cs and put it under
App_Code, Intellisense picks it up, and you now have access to its members.

It appears you cannot add any of your own methods (or enums, etc) to the
inline version created through the VS 2005 add file wizard. Probably
because the inline version doesn't define the Global class.

Ronnie

Brock Allen wrote:
Ah, I bet you're trying it from codebehind? My tests were all from
codeinside in my ASPX.

So, you can build a codebehind for your global.asax like the "olden days"
:). Make a class in the App_Code folder called "Global" that inherits
:HttpApplication.
In your global.asax add an Inherits="Global" directove. Then your
codebehind classes can see/use the Global class in App_Code.

Now having done all of that, I'm not sure why putting code there is any
different or any more useful than simply putting that code into its own
class (not global.asax related) in App_Code. What's your motivation for
making that code in global.asax (I've lost the original post)?

-Brock
DevelopMentor
http://staff.develop.com/ballen
It's not a namespace, it's the name of the class generated from the
global.asax. I just tested it locally and it was functional. I'm
wondering what might be different....

-Brock
DevelopMentor
http://staff.develop.com/ballen
Global_asax isn't a valid namespace either, so that doesn't work.

Ronnie

Nov 19 '05 #7
> It appears you cannot add any of your own methods (or enums, etc) to
the inline version created through the VS 2005 add file wizard.
Probably because the inline version doesn't define the Global class.


You can and the inline does define the class, it's just that the codebehind
classes don't reference that generated assembly. That's why when I was working
with the all codeinside model it was working for me as they do reference
the generated assembly.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #8
It's just, moving the code behind Global.asax.cs file to App_Code isn't
really a good choice for me at the moment (although I don't seem to have
much of a choice).

All my troubles began when I started migrating a medium sized web
application from .Net 1.1 to 2.0.

Microsoft's idea of the App_Code directory storing the model, as I
understand it, isn't that great for existing applications. If parts of the
model references parts of the GUI, you're in for trouble, because App_Code
contained classes are not allowed to access outside classes.

This will break a lot of application, and require a lot of work to migrate
properly.

My initial solution, after running the migration wizard, was to move all
files out of the App_Code directory back into the parent directory
(retaining the directory structure). This way, the directory structure now
resembles that of the .Net 1.1 application, and I'm not using the App_Code
directory.

So, moving Global.asax.cs to App_Code just gives me more trouble as
Global.asax.cs references classes that are not in App_Code. Of course, you
can move these classes to App_Code, but they reference other classes, that
reference other classes, and so on.

The optimal solution would be to have ones application running under .Net
2.0 and then optionally move code to App_Code as you get your code
refactored.

Ronnie

Brock Allen wrote:
It appears you cannot add any of your own methods (or enums, etc) to
the inline version created through the VS 2005 add file wizard.
Probably because the inline version doesn't define the Global class.


You can and the inline does define the class, it's just that the
codebehind classes don't reference that generated assembly. That's why
when I was working with the all codeinside model it was working for me as
they do reference the generated assembly.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #9
re:
The optimal solution would be to have ones application running under
.Net 2.0 and then optionally move code to App_Code as you get your
code refactored.
That makes sense.

Have you suggested that, or filed a bug report,
at the MSDN Product Feedback Center ?

http://lab.msdn.microsoft.com/productfeedback/

You should.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Ronnie" <r_******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... It's just, moving the code behind Global.asax.cs file to App_Code isn't
really a good choice for me at the moment (although I don't seem to have
much of a choice).

All my troubles began when I started migrating a medium sized web
application from .Net 1.1 to 2.0.

Microsoft's idea of the App_Code directory storing the model, as I
understand it, isn't that great for existing applications. If parts of the
model references parts of the GUI, you're in for trouble, because App_Code
contained classes are not allowed to access outside classes.

This will break a lot of application, and require a lot of work to migrate
properly.

My initial solution, after running the migration wizard, was to move all
files out of the App_Code directory back into the parent directory
(retaining the directory structure). This way, the directory structure now
resembles that of the .Net 1.1 application, and I'm not using the App_Code
directory.

So, moving Global.asax.cs to App_Code just gives me more trouble as
Global.asax.cs references classes that are not in App_Code. Of course, you
can move these classes to App_Code, but they reference other classes, that
reference other classes, and so on.

The optimal solution would be to have ones application running under .Net
2.0 and then optionally move code to App_Code as you get your code
refactored.

Ronnie

Brock Allen wrote:
It appears you cannot add any of your own methods (or enums, etc) to
the inline version created through the VS 2005 add file wizard.
Probably because the inline version doesn't define the Global class.


You can and the inline does define the class, it's just that the
codebehind classes don't reference that generated assembly. That's why
when I was working with the all codeinside model it was working for me as
they do reference the generated assembly.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #10
> So, moving Global.asax.cs to App_Code just gives me more trouble as
Global.asax.cs references classes that are not in App_Code. Of course,
you can move these classes to App_Code, but they reference other
classes, that reference other classes, and so on.


We still haven't established why the code is in global.asax in the first
place if it's simply meant to be helper code accessible to the entire application.
I probabaly wouldn't have put it there using the v1.1 model, so maybe this
is an edge case that wasn't considered when they were architecting v2.0.
I understand this is existing code, so perhaps you're not in a position to
rearchitect.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #11

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

Similar topics

2
by: Nattydreadlock | last post by:
Hello, I tried to convert my ASP.NET 1.1 project to ASP.NET 2.0. Apart from some warnings most things went fine. There was one error though. When I try to run my project it keeps saying:...
1
by: noname | last post by:
i have the following in global.asax: <%@ Application Codebehind="Global.asax.cs" Inherits="Foo.Global" Classname="AppClass" %> but wherever i use AppClass.foo() i get the compiler error: The...
5
by: WJ | last post by:
I am attempting to use the Global.Asax to store my user's configuration. Here is the concept: 1. User logs on into the site using Form Authentication. 2. I capture the user Credential, verify it...
2
by: Norton | last post by:
I understand how to create HTTP modules that can be used to add functionality to a website but there are a few things I don't understand. If I create an HTTP Module and I want it to intercept a...
1
by: fd123456 | last post by:
Hi tshad, sorry for not coming back to you earlier. When I meant to add a method to Global.asax, I actually meant to add it to the code-behind file. If you click on "Global.asax" in the file...
4
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 ......
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
5
by: rote | last post by:
I'm using ASP.NET 2.0 and i have copied and pasted the code below to my Global.asax file but it desn't trap the error I want to trap the 401 access denied void Application_Error(object sender,...
1
by: daonho | last post by:
Hi Everyone, I have encountered this problem that I am not able to figure out. Please drop me some lines if you have any idea how to solve this issue. I have a global.asax file in my web site. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.