Application Object Again!!!

A

Adam Knight

Hi all,

I am still unable get retrieve an Application variable in .NET.

I can use the Session object by just typing.. Session("myVar") in aspx or
..vb.
However, using Application("myVar") results in nothing.

I have tried executing the following code..but nothing is outputted.

If Application("UrlPrefix") Is Nothing Then
Response.Write("<NULL>")
Else
Response.Write("Type: " & Application("UrlPrefix").GetType().Name & ",
Value: """ + Application("UrlPrefix").ToString() + """")
End If

If i include this code.. 'Response.Write(Application.Keys.Count) i get 0

So either the application object is not being created ..or it needs to be
referenced some how..

Am i missing something here?

The code is contained in a .vb file used for a user control.

These are the imports i am using, in case they are relevant.
Imports Microsoft.VisualBasic
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls

Would appreciate any help to get beyond this.!!!

Cheers,
Adam
 
J

jianglinchun

You mean that even code like this will not run as expected?

Application("mykey") = "value";
Response.Write( Application("mykey") );

I think you should check the exactly excute path during the request.
The application variables may not been initilized correctly.

Regards!
(e-mail address removed)
 
J

Juan T. Llibre

re:
However, using Application("myVar") results in nothing.

You cannot initialize Application variables in code.
They can only be initialized in global.asax.

You can *assign a value* to an Application variable in code,
but you cannot create an Application variable in code.

Is that what you've been trying to do ?
Or, are you attempting to assign a value to an already-created App var ?

What happens if you run :

Dim AppVarCount As String = Application.Contents.Count.ToString()
Response.Write(AppVarCount)

?



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/
======================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top