Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Application variable question (conversion from asp to dotnet)

Reply
Thread Tools

Application variable question (conversion from asp to dotnet)

 
 
Goober
Guest
Posts: n/a
 
      02-10-2005
I converted a website that was done in ASP to dotnet, and brought over a
number of items, some of which don't appear to work in the same way on
dotnet as they did on ASP.

One of them is an application variable.

I have this code in my global.asax in the Sub Session_Start:

Application.Lock() 'Add 1 to active visitor count when new visitor
Application("counter99") = Application("counter99") + 1
Application.UnLock()

It's a counter that I increment each time a user logged in to my old ASP
site.

I have this in the Sub Session_OnEnd to decrement the same counter:

Sub Session_OnEnd(ByVal sender As Object, ByVal e As EventArgs)
Application.Lock() 'Sub 1 active visitor count when new visitor
Application("counter99") = Application("counter99") - 1
Application.UnLock()
End Sub

I know that in ASP, you couldn't really rely on the session end to get a
"good" accurate count on users, but in ASP, it generally worked, and
gave you a reasonable estimate of how many users were hitting the site
at a time.

In dotnet, this counter registers a number exponentially higher than
what it did in ASP.

Is there a way I can implement a counter for current users of the
website that would be a tad more accurate than this?

Any help appreciated.

Thanks

BC
 
Reply With Quote
 
 
 
 
John Timney \(ASP.NET MVP\)
Guest
Posts: n/a
 
      02-10-2005
The code below should help you..

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

---somepage.aspx -----

<html>

<script language="VB" runat="server">
Sub Page_Load(Src as object, E as EventArgs)
MyGlobals.UserCount +=1
Response.Write(MyGlobals.UserCount.ToString())
End Sub

</script>
<body style="font: 10pt verdana">
Timneys Test
<form runat="server">
</form>


</body>
</html>


---global.asax----------

<%@ Application Classname="MyGlobals" %>
<script language="VB" runat="server">

public shared UserCount as integer = 1

Sub Application_OnStart()
' Application startup code goes here.
End Sub

Sub Session_OnStart()
' Session startup code goes here.

Application.Lock()
Application("SomeGlobalCounter") =
CType(Application("SomeGlobalCounter"),Integer) + 1
Application.UnLock()

End Sub

Sub Session_OnEnd()
' Session cleanup code goes here.
End Sub

Sub Application_OnEnd()
' Application cleanup code goes here.
End Sub

</script>








"Goober" <(E-Mail Removed)> wrote in message
news:ubI%(E-Mail Removed)...
> I converted a website that was done in ASP to dotnet, and brought over a
> number of items, some of which don't appear to work in the same way on
> dotnet as they did on ASP.
>
> One of them is an application variable.
>
> I have this code in my global.asax in the Sub Session_Start:
>
> Application.Lock() 'Add 1 to active visitor count when new visitor
> Application("counter99") = Application("counter99") + 1
> Application.UnLock()
>
> It's a counter that I increment each time a user logged in to my old ASP
> site.
>
> I have this in the Sub Session_OnEnd to decrement the same counter:
>
> Sub Session_OnEnd(ByVal sender As Object, ByVal e As EventArgs)
> Application.Lock() 'Sub 1 active visitor count when new visitor
> Application("counter99") = Application("counter99") - 1
> Application.UnLock()
> End Sub
>
> I know that in ASP, you couldn't really rely on the session end to get a
> "good" accurate count on users, but in ASP, it generally worked, and
> gave you a reasonable estimate of how many users were hitting the site
> at a time.
>
> In dotnet, this counter registers a number exponentially higher than
> what it did in ASP.
>
> Is there a way I can implement a counter for current users of the
> website that would be a tad more accurate than this?
>
> Any help appreciated.
>
> Thanks
>
> BC



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
Public variable = application("variable") ? THY ASP .Net 3 09-04-2006 03:15 PM
SqlConnection Object in Application Variable OR Session Variable OR open/close pratham ASP .Net 3 08-31-2006 07:26 PM
Asp.net application inside another Asp.net Application Ameen ASP .Net 3 10-18-2005 03:39 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments