473,320 Members | 1,821 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,320 software developers and data experts.

Accessing variables declared in Global.asax.vb

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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
2 5157
Hi,

Global.asax is a class that is always called before your page is loaded, but
it's not part of of your page really. (Master page in asp.net 2.0 will be
more what you are looking for)

The only thing I know you can access from global.asax are Public Shared
(Static in c#) functions or variables.

Using shared variable must be considered very dangerous because they are
often source of non-thread safe result. If you want to carry information
between page, better look into Session variable.

Hope that help you,

-----------------------
Jean-Claude Morin, MCAD
Software Developer
2k1Soft/kCentric, Canada
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ee****************@TK2MSFTNGP10.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
Hi Nathan,

A file is code. It does not have anything to do with the program, other than
the fact that the code in it is compiled into one. The global.asax file is
all code. It will help if you understand this, as well as what it creates
when compiled, which is what you need to be concerned about.

The global.asax file is a code file that defines a class. This class is used
at run-time to fire events that occur during the lifetime of your app. The
name of the class is "global" - not "global.asax," as "global.asax" is a
file name. I hope I'm getting this across clearly. The class is used by the
ASP.Net worker process during its lifetime, that is, the lifetime of the
ASP.Net application, which lives from the moment the first Request to your
application occurs, until 20 minutes (default) after the last Request
occurs, or whenever the web server is restarted, or, on a Windows 2003
server, whenever the Application Pool for your ASP.net app is recycled.

It contains a number of event handlers, which are pre-wired by the ASP.Net
ISAPI, to be fired at certain times during the lifetime of your ASP.Net app.
Each of these event handlers is a method (a function, if you will). Any
variables declared inside a method are scoped locally to that method. That
is, they do not exist when the method exits, just as they would in any other
class method.

I'm just trying to give you some background here, so that you will
understand better, and hopefully not encounter this situation again in some
different form.

So, as to the answer, let's start by forgetting that these variables and
functions are declared in the global.asax file. They are members of a class.
Yes, the class is named "global" but that doesn't mean that everything in it
IS global. However, these event handers give you an opportunity to CREATE
some global variables. The global class has access to the Application Cache,
which lives for the entire lifetime of your application, and is, in fact,
accessible to all pages and classes used in your application. In addition,
several event handlers in the global class have access to user-specific
"global" cache, that is Session state. If you want to persist something in
state that is accessible only to one user client, and only for the time for
which that user client is connected, store it there.

Of course there are other state mechanisms that have nothing to do with the
global class, or global event handlers, such as ViewState, which is
Page-specific.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ee****************@TK2MSFTNGP10.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3

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

Similar topics

25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
1
by: Dan | last post by:
I'm not able to access my variables that I've set in my global.asax. Here is my simple code. Note: Error message is below. ] <%@ Page Language="c#" %> <script language="c#" runat="server">
2
by: Ekul | last post by:
I have an application that allows users to login and logout. I track how many users are logged in and when each individual is logged in. The application will not allow concurrent logins(let a...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
1
by: WJ | last post by:
I am storing my global variables in the application "global.asax" file, some are nd some are not sensitive. Is it OK to store sensitive data on Global variables. Please note: some are created at...
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
1
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...
5
by: John | last post by:
Hi Is there a way to declare public functions that can be accessed in any aspx page? Can global variables be declared? Thanks Regards
10
by: Yehia A.Salam | last post by:
Hello, I was trying to connect to an Xml database, and I thought of loading the Xml Document in "Application_Start" so that the xml is loaded only once and then queried later as many times as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.