|
 |
aspx thread: Re: who is online?
Message #1 by rabihy@h... on Mon, 4 Mar 2002 14:37:50
|
|
Hello My Friends,
I have reached a way to resolve my problem. I am attaching the source code
of Global.asax that access an XML file whoisonline.xml and store the
online poeple as :
<?xml version="1.0" standalone="yes"?>
<whoisonline>
<profile>
<id>1</id>
<headline>Text Here</headline>
</profile>
</whoisonline>
Global.asax
Sub Session_End()
If Context.Request.IsAuthenticated Then
Application( "SessionCount" ) -= 1
Dim myDateSet = New DataSet()
myDateSet.ReadXml("M:\database\whoisonline.xml")
Dim myTable As DataTable = myDateSet.Tables("profile")
Dim id as string = Cstr(Context.User.Identity.Name)
Dim myDatarow as DataRow
For Each myDatarow in myTable.Rows
If myDatarow(0).ToString() = Id then
myDatarow(0).Delete()
Exit For
End If
Next
myDateSet.WriteXml("M:\database\whoisonline.xml")
End If
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
If Context.Request.IsAuthenticated Then
If Application( "SessionCount" ) Is Nothing Then
Application( "SessionCount" ) = 0
End If
Application( "SessionCount" ) += 1
Dim myDateSet = New DataSet()
myDateSet.Readxml("M:\database\whoisonline.xml")
Dim myTable As DataTable = myDateSet.Tables("profile")
Dim strExpr as String
strExpr = "id = " & Context.User.Identity.Name
Dim foundRows() As DataRow
foundRows = myTable.Select(strExpr)
If foundRows.GetUpperBound(0) < 0 then
Dim myRow As DataRow
myRow = myTable.NewRow()
myRow("id") = Context.User.Identity.Name
Dim objFormsID As FormsIdentity
objFormsID = Context.User.Identity
myRow("headline") = objFormsID.Ticket.UserData
myTable.Rows.Add(myRow)
End If
myDateSet.WriteXml("M:\database\whoisonline.xml")
End If
End Sub
I have tried to store them as array in Application, but it was not much
reliable. So i thought of storing it in XML file. Do you think it is
better to store them as XML? or SQLServer Table? Is there any suggestions
for enhancing the above coding? thank you in advance...
Rabih
Message #2 by ToddC@m... on Mon, 4 Mar 2002 13:00:36 -0600
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C1C3AE.DE694010
Content-Type: text/plain
I think the big problem with the XML file is keeping it clean.
You will have abandoned sessions, and the XML file will have to be cleaned
out. Beware while you are cleaning others are adding to it. You would have
to stop the process to clean out the files.
You have little or no transactional integrity (two people log in at the same
time, or close enough).
Creating a DataSet, to manipulate an XML document just might be the most
expensive way to do it. Especially every time someone was authenticated.
You would have to write your own locking algorithm to keep the file from
getting trashed, etc.
In all, I would use a SQL Table. Passes the ACID test, provides all the
locking, and can handle marshaling simultaneous requests.
tc
-----Original Message-----
From: rabihy@h... [mailto:rabihy@h...]
Sent: Monday, March 04, 2002 8:38 AM
To: ASP+
Subject: [aspx] Re: who is online?
Hello My Friends,
I have reached a way to resolve my problem. I am attaching the source code
of Global.asax that access an XML file whoisonline.xml and store the
online poeple as :
<?xml version="1.0" standalone="yes"?>
<whoisonline>
<profile>
<id>1</id>
<headline>Text Here</headline>
</profile>
</whoisonline>
Global.asax
Sub Session_End()
If Context.Request.IsAuthenticated Then
Application( "SessionCount" ) -= 1
Dim myDateSet = New DataSet()
myDateSet.ReadXml("M:\database\whoisonline.xml")
Dim myTable As DataTable = myDateSet.Tables("profile")
Dim id as string = Cstr(Context.User.Identity.Name)
Dim myDatarow as DataRow
For Each myDatarow in myTable.Rows
If myDatarow(0).ToString() = Id then
myDatarow(0).Delete()
Exit For
End If
Next
myDateSet.WriteXml("M:\database\whoisonline.xml")
End If
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
If Context.Request.IsAuthenticated Then
If Application( "SessionCount" ) Is Nothing Then
Application( "SessionCount" ) = 0
End If
Application( "SessionCount" ) += 1
Dim myDateSet = New DataSet()
myDateSet.Readxml("M:\database\whoisonline.xml")
Dim myTable As DataTable = myDateSet.Tables("profile")
Dim strExpr as String
strExpr = "id = " & Context.User.Identity.Name
Dim foundRows() As DataRow
foundRows = myTable.Select(strExpr)
If foundRows.GetUpperBound(0) < 0 then
Dim myRow As DataRow
myRow = myTable.NewRow()
myRow("id") = Context.User.Identity.Name
Dim objFormsID As FormsIdentity
objFormsID = Context.User.Identity
myRow("headline") = objFormsID.Ticket.UserData
myTable.Rows.Add(myRow)
End If
myDateSet.WriteXml("M:\database\whoisonline.xml")
End If
End Sub
I have tried to store them as array in Application, but it was not much
reliable. So i thought of storing it in XML file. Do you think it is
better to store them as XML? or SQLServer Table? Is there any suggestions
for enhancing the above coding? thank you in advance...
Rabih
|
|
 |