question on global.ascx

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i want to keep a global variable or a session in global.ascx when ever a user
access this particular page. at certain time, this page will do a infinit
loop, and i want to set a variable to allow it to only loop how many times i
want. e.g 3 times and quit. how can i get this done?
 
Asha,
You ask an interesting (as in odd) question. First off, if this is for a
particular page, why not place it in this page, instead of the Application?
Also, why do you have code that does infinite loop? is this a bug or by
design? I think you might be trying to solve your problem the wrong way.

However, without knowing more about your problem, I might try something like
this:

Global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim path As String = Request.Url.AbsolutePath
If path.ToUpper() = "/PATH/PAGE.ASPX" Then
Context.Items.Add("maxLoop",
System.Configuration.ConfigurationSettings.AppSettings("maxLoop"))
End If
End Sub

your page:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim maxLoop as integer = cint(Context.Item("maxLoop"))
End Sub


Again, not sure why you want to use global.asax for this and not do the
logic in the page, and also not sure this is even the right way to solve
your problem.

Karl
 
Back
Top