Log users / Counter

ImDaFrEaK

Well-known member
Joined
Jan 7, 2006
Messages
416
Location
California
Programming Experience
5-10
I would like to Log each time a user enters my site to a text file and I would also like to put a counter on my site to show how many times it has been visited.

I know this is probably simple but I have had a problem doing it. For example. I put the following code into my Page_Load event and it only worked for me during testing. Gave others an error.

'please ignore if the parameters in the FileStream Object are out of place or type wrong I am doing this at work and can't remember the exact syntax but I know it's correct at home.
VB.NET:
Dim FS as new FileStream(Server.MapPath("Bin/Log.txt"), File.Append, Access.Write, Share.none)
Dim SW as new StreamWriter(FS)
SW.Writeline(User.Identity.Name & " / " & Date.Now.toString)
SW.Close()
SW.Flush()

That code only works for me but not other users.
 
I'm not much on the ASP.NET side of things yet, but that seems highly problematic. It would see you are basically allowing modification on the server, but also, opening the possibility of attempting two simultaneous writes.

Why not keep this in a database instead?
 
Back
Top