Application variables in ASP.Net

hankthetank

Newcomer
Joined
Feb 26, 2004
Messages
13
Location
Melbourne, Australia
I have created several Application variables in an ASP.Net solution. I can manipulate these variables fine in a Web Form code-behind page but for some reason I get an error when I try to use them in a VB code page.

I am converting ASP pages to .Net and I have converted any ASP include pages into a Public Class in a .vb page. For example;

index.aspx.vb
Code:
Public Class Index
  Inherits System.Web.UI.Page

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Response.Write (Application("CommsURL"))         ' this works fine

    Dim clsOption As New _Option
    Response.Write (clsOption.DisplayAppVar())
    clsOption = Nothing
  End Sub
End Class

option.vb (this was previously the ASP include file)
Code:
Public Class _Option
  Inherits System.Web.UI.Page

  Public Function DisplayAppVar()
    DisplayAppVar = Application("CommsURL")           ' this generates an error
  End Function  

End Class

The error generated by the line above is "System.NullReferenceException: Object reference not set to an instance of an object."

I have tried creating an instance of the System.Web.HttpApplication class as follows ;

Code:
Dim clsHttpApp as new System.Web.HTTPApplication
DisplayAppVar = clsHttpApp.Application("CommsURL")

but still get the same error.....Can anyone please help??? I'm tearing my hair out here!!

Thanks
Matt
 
Dim c As New Class1(Application)
Label1.Text = c.run()




Public Class Class1
Dim appweb As Web.HttpApplicationState
Sub New(ByVal app As Web.HttpApplicationState)
appweb = app
End Sub
Public Function run() As String
Return appweb.Item("test")







End Function
End Class
 
This is beter

Public Class Class1

Sub New()

End Sub
Public Function run() As String

Return HttpContext.Current.Application("test")

End Function
End Class
 
Back
Top