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

how to expose a variable with global.asax?

D.
Hi,

I need to expose a variable to every aspx file of the applicationroot.
I tried with global.asax like this:
<%@ Application Language="VB" %>
<script runat="server">
public a as string
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
a="ok"
End Sub
</script>

When running an aspx-file in the applicationroot with this code:
<%@ Page Language="VB" %>
<%@ import namespace ="System.Web.UI.Page" %>
<% Response.Write(a)%>

i get the error: "Name 'a' is not declared"

Thanks for help
Dominique
May 12 '06 #1
5 1336
"D." <d.***@rtt.com> wrote in message
news:Oz****************@TK2MSFTNGP05.phx.gbl...

Try: <% Response.Write(Global.a.ToString) %>
May 12 '06 #2
Since ur hooking into Application_Start, I'll assume this is a shared
variable for all users of your site. If so, the simplest solution is to
store it in the application object:
Application.Add("SomeKey", "ok")

which you can then retrieve via:
cstr(Application("SomeKey"))
If this is a per-user/request, hook into the Application's BeginRequest and
store it in the Context.Items collection..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"D." <d.***@rtt.com> wrote in message
news:Oz****************@TK2MSFTNGP05.phx.gbl...
Hi,

I need to expose a variable to every aspx file of the applicationroot.
I tried with global.asax like this:
<%@ Application Language="VB" %>
<script runat="server">
public a as string
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
a="ok"
End Sub
</script>

When running an aspx-file in the applicationroot with this code:
<%@ Page Language="VB" %>
<%@ import namespace ="System.Web.UI.Page" %>
<% Response.Write(a)%>

i get the error: "Name 'a' is not declared"

Thanks for help
Dominique

May 12 '06 #3
My personal preference would be to create my own class (possibly exposing
Items in a strongly type manner as explained by Karl).

This way you don't have to cast here an there from the exposed application
object plus it's likely not related to the application in the IIS sense but
ather from business point fo view...

--

"D." <d.***@rtt.com> a écrit dans le message de news:
Oz****************@TK2MSFTNGP05.phx.gbl...
Hi,

I need to expose a variable to every aspx file of the applicationroot.
I tried with global.asax like this:
<%@ Application Language="VB" %>
<script runat="server">
public a as string
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
a="ok"
End Sub
</script>

When running an aspx-file in the applicationroot with this code:
<%@ Page Language="VB" %>
<%@ import namespace ="System.Web.UI.Page" %>
<% Response.Write(a)%>

i get the error: "Name 'a' is not declared"

Thanks for help
Dominique

May 12 '06 #4
D.
Thanks all

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:eC*************@TK2MSFTNGP04.phx.gbl...
Since ur hooking into Application_Start, I'll assume this is a shared
variable for all users of your site. If so, the simplest solution is to
store it in the application object:
Application.Add("SomeKey", "ok")

which you can then retrieve via:
cstr(Application("SomeKey"))
If this is a per-user/request, hook into the Application's BeginRequest and store it in the Context.Items collection..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"D." <d.***@rtt.com> wrote in message
news:Oz****************@TK2MSFTNGP05.phx.gbl...
Hi,

I need to expose a variable to every aspx file of the applicationroot.
I tried with global.asax like this:
<%@ Application Language="VB" %>
<script runat="server">
public a as string
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
a="ok"
End Sub
</script>

When running an aspx-file in the applicationroot with this code:
<%@ Page Language="VB" %>
<%@ import namespace ="System.Web.UI.Page" %>
<% Response.Write(a)%>

i get the error: "Name 'a' is not declared"

Thanks for help
Dominique


May 12 '06 #5
D.
Karl,

I tried what you proposed and it works.
But i also tried with cookies.
What would you advice to use?
Thanks

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:eC*************@TK2MSFTNGP04.phx.gbl...
Since ur hooking into Application_Start, I'll assume this is a shared
variable for all users of your site. If so, the simplest solution is to
store it in the application object:
Application.Add("SomeKey", "ok")

which you can then retrieve via:
cstr(Application("SomeKey"))
If this is a per-user/request, hook into the Application's BeginRequest and store it in the Context.Items collection..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"D." <d.***@rtt.com> wrote in message
news:Oz****************@TK2MSFTNGP05.phx.gbl...
Hi,

I need to expose a variable to every aspx file of the applicationroot.
I tried with global.asax like this:
<%@ Application Language="VB" %>
<script runat="server">
public a as string
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
a="ok"
End Sub
</script>

When running an aspx-file in the applicationroot with this code:
<%@ Page Language="VB" %>
<%@ import namespace ="System.Web.UI.Page" %>
<% Response.Write(a)%>

i get the error: "Name 'a' is not declared"

Thanks for help
Dominique


May 12 '06 #6

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

Similar topics

4
by: Me_Titus | last post by:
I would like to know if there is any kind of difference between an empty web project and an web application project other than all the files stucked toghether to the web application project. I am...
6
by: Water Cooler v2 | last post by:
I want to take a global variable in my ASP.NET application. How do I make it global so that it is accessible to all the pages in my application? Do I put it in the Global.asax file? If so,...
2
by: simon | last post by:
hello, what i'm looking to do is store the path of the app on a the server for reuse in the site. my thoughts so far are... -make a key in the web.config file -retrieve the value in globals.asax...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
16
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: <%@...
13
by: michel | last post by:
Hi, i created a class 'test' with a method 'descrlimit()' (no matter). That method is used in a lot of pages in the application, so i need to put this code a lot of time: "Dim odescr As New...
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...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
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...
5
by: baburmm | last post by:
Hai, I want to get the Global static name(for Constant) Declared in the Global.asax file for my whole project as a constant. my coding in the Global.asax file is private static string strName =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...

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.