473,289 Members | 2,040 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,289 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 1334
"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 =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.