Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2005, 04:43 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default find if a user/ ip is connected

i posted this in one section already, but i think it might not be the bast place to put it, so i'm putting it here too:
Ok, i'm new to aspx, but i'm a fast learner, real fast. but i came across a problem i haven't yet found any reference material on... and i've yet to figure it out. here's what i WANT to do: store some kind of variable in the database, that will be read from later, by another user(via the asp script) that will used to estimate if you user who's profile they're viewing is still online... OR, query the server (iis) to see if the ip addy associated with that user is still connected. i don't know what, if any, are the functions i call to see if an ip is connected, so for the last while, i've been using the now() function, to write an entry in the database, under that users name, and when you come across thier profile, it will get that value for that user out of the database, and see if it is withing five minuites of now(), and if so, they are (probably) still online. then problem with that? now() uses the CMOS clock, and not the windows settings you have, so setting it to military time won't help. ya know user1's time in the database is 12:59 (trim the am and pm) and user2 accesses user1's page at 01:01 (pm), well it's technically a smaller number, muuuuch smaller than five minuites. ok. so, is there a way (once id changed the script to write the users ip at logon, instead of the trimmed now() function), to get the users ip addy with your script? i know there HAS to be, i see all kinds of chineese example for doing that in java, but i don't write java, or read japaneese. do i need to import any other namespaces other than my oledb to get the ip function? also, not that i'll need an answer to this if you can answer my previous question, but if there is no way to do what i want, then is there a way to user the WINDOWS clock instead of the CMOS? thanks in advance. to see an example of what i'm trying to perfect, check out my site at http://www.profiles.grimmusic.com thanks again.
p.s. is there any kind of timer function in asp?

[email protected]
WWW.GRIMMUSIC.COM
__________________
---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old February 2nd, 2005, 05:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Request.UserHostAddress.ToString() for IP
http://www.c-sharpcorner.com/Code/20...bSiteStats.asp

If you are using FormsAuthentication you could update a user's profile once they log on to 1 and 0 when they click logoff. (But not everybody clicks logoff. Some simply close the browser.) Then check for all users who have loggedon status of 1.

 
Old February 3rd, 2005, 05:12 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

well i already knew that, but the problem is, like you said, and i was saying somewhere else, "NOONE LOGGS OFF" so it's kinda hard to write a zero when there's no "EVENT" to tell it to write the zero. know what i mean?

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 05:13 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

hey, i'm sorry, i JUST seen your referance link about the ip question, thatnks dude, i apreciate that. it will be very usefull.

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 02:21 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

how would i use that ip addy to query the server? what i'm asking is suppose i use the ip, and the entry for THEIR ip is 65.27.128.156, how would i ask my server if that ip is still connected? or would i ask if it's active? etc? thanks.

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 08:51 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

OK, well i got the jist of the session_onstart , and i have it write a value based of a cokkie on thier pc in the apropriate field, but the problem is, the session_onend isn't writing IT'S value when, and if, it's getting triggered. i have set my iis properties to timeout at 1 minuite, and in my global.asax for 1 min, but it's not writing the value i told it to, BUT, if i trigger the session_on end event manually eg, but putting it int the session_onstart event somewhere before the end sub, it DOES execute and write the script, so....... something isn't telling it to time out? what could it be? i have it set for 1 min, in both the global and iis, and i'm testing it with 2 different pc's, am i missing something? here is the script, in case you wanna check it out:
*******************************
<%@ IMPORT NAMESPACE="SYSTEM.DATA"%>
<%@ IMPORT NAMESPACE="SYSTEM.DATA.OLEDB"%>
<%@ LANGUAGE="VBscript" %>
<script language="VB" runat="server">
Sub Application_OnStart
Application("Active")=0
End Sub

Sub Application_OnEnd
'no code is needed here
End Sub


Sub Session_OnStart
Session.Timeout=1
Session("Start")=Now
Application.Lock
Application("Active")=Application("Active")+1
dim this



IF REQUEST.Cookies ("CK") IS NOTHING THEN
RESPONSE.REDIRECT("LOGIN.ASPX")
ELSE
APPLICATION("CK") = REQUEST.Cookies ("CK")("UID").TOSTRING()
DIM UID = REQUEST.Cookies("CK")("UID")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='YES' WHERE UNAME = '" & UID &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING

Application("this") = Session.SessionID
END IF

'SESSION_ONEND
Application.unlock
End Sub




Sub Session_OnEnd
Application.Lock
Application("Active")=Application("Active")-1
dim this
Application("this") = Session.SessionID


IF REQUEST.Cookies ("CK") IS NOTHING THEN
RESPONSE.REDIRECT("LOGIN.ASPX")
ELSE
APPLICATION("CK") = REQUEST.Cookies ("CK")("UID").TOSTRING()
DIM UID = REQUEST.Cookies("CK")("UID")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='NO' WHERE UNAME = '" & UID &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING
END IF
Application.unlock

End Sub

</SCRIPT>
*******************************
thanks for your time.

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 4th, 2005, 12:53 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

OK, I DON'T KNOW WHY NOONE AT ANY OF THE FORUMS KNEW MUCH ABOUT THE SESSION_ONEND EVENT (OR RATHER "SUBROUTINE") OTHER THAN THE FACT THAT IT'S <b>ENTIRELY</B> UNRELIABLE. BUT I FIGURED OUT A LOT ABOUT IT, AND WHAT YOU <B>CAN</B> AND <B>CANNOT</B> DO WITH IT, BY USING A BIT OF LOGIC. I KNOW I'VE GOTTEN A LOT OF PEEOPLE WHO TRIED TO HELP ME, MOSTLY TO NO AVAIL, BECAUSE NOONE UNDERSTOOD THE CAPABILITIES, AND PARAMATER LIMITS, OF THIS EVENT, AS MUCH AS WAS REQUIRED TO IN ORDER TO RESOLVE THIS ISSUE, (WHICH I FOUND OUT, THE INTERNET FORUMS ARE <B>FILLED</B> WITH PEOPLE WANTING TO DO THE SAME THING, BUT FOR SOME REASON, NOONE WAS ABLE TO HELP, I GUESS EITHER NOONE KNOWS THIS TRICK, OR ALL THE PEOPLE WHO DO AREN'T TALKING). OK NOW, FOLLOW ALONG:
************************************************** ************
MY TUTORIAL FOR MAKING SURE THE DB ENTRY IS MADE FOR A USER WHO DID NOT LOG OUT WITH THE LOGOUT BUTTON, (EG. LEFT THE SITE, OR CLOSED THE BROWSER);
************************************************** ************
OK, NOW I KNOW FROM BEING ALL OVER THE NET, SEARCHING FOR A RESOLOUTION, BEFORE I GAVE UP AND JUST SAT HERE TILL I FIGURED IT OUT, THAT ALMOST ALL OF YOU HAVE SEEN THE VERY POPULAR CODE EXAMPLE FOR FINDING THE NUMBER OF CURRENT USERS CONNECTED, IT USES THE APPLICATION("YOUR VARIABLE NAME HERE") VARIABLE IN INCREMENT THE NUMBER OF USERS HOLDING A SESSION ID, WELL IF YOU LOOK IN THAT EXAMPLE, YOU'LL SEE THAT THE SEESION_ONEND EVENT IS ACTUALLY EXECUTING <B>SOMETHING</B>, SO YOU KNOW YOU CAN EXECUTE A SCRIPT IN IT. NOW WHAT A LOT OF PEOPLE HAVEN'T FIGURED OUT, IS THAT YOU <B>CANNOT</B> USE A REPLY OR REQUEST METHOD IN THAT EVENT. ALSO, IT IS NOT THE NETWORK SERVICE OR IUSER THAT IS USING A PERMISSION TO EXECUTE THAT EVENT, IT IS ACTUALLY THE "LAUNCH IIS PROCESS ACCOUNT (IWAM_YOURPCNAME)" SO YOU'LL HAVE TO SET THE PERMISSION SETTINGS FOR THE DIRECTORY THAT THE DB IS IN TO ALLOW THAT ACCOUNT TO EDIT IT'S CONTENTS, FOR SOMPLICITY, I ALLOWED THAT PERMISSION TO THAT ACCOUNT FRO THE WHOLE DIRECTORY CONTIANING THE DB AND THE GLOBAL.ASAX FILE. NOW, BACK TO THE COUNTER EXAMPLE, YOU SEE IN THE EXAMPLE, WHERE IT STORES, IN THE SESSION_ONSTART EVENT, A VARIABLE TO THE APPLICATION("YOURVARIABLENAME") VARIABLE? WELL YOU REMEMBER HOW IN THAT EXAMPLE, YOU CALLED TO THAT VARIABLE FROM YOUR ASP OR ASPX PAGE? EG: "<%= RESPONSE.WRITE (APPLICATION("MYVARIABLENAME").TOSTRING)?
OK, WELL NOW IF YOU THINK ABOUT IT, THAT MEANS THAT THE APPLICATION VARIABLE IS ACCESABLE OUTSIDE OF THE SESSION_ONSTART SUBROUTINE. SO THEN, WHY CANT WE USE THAT VARIABLE IN THE SESSION_ONEND SUBROUTINE, SINCE WE <b>CAN'T</B> USE SOMETHING LIKE "REQEST.COOKIE" OR "RESPONSE.REDIRECT"? WELL THE GOOD NEW IS: YOU CAN. AND HERE'S HOW I DID IT:
************************************************** ************

<%@ IMPORT NAMESPACE="SYSTEM.DATA"%>
<%@ IMPORT NAMESPACE="SYSTEM.DATA.OLEDB"%>
<%@ LANGUAGE="VBscript" %>
<script language="VB" runat="server">

Sub Application_OnStart
Application("Active")=0
End Sub

Sub Application_OnEnd
'no code is needed here
End Sub


Sub Session_OnStart
Session.Timeout=1
Session("Start")=Now
Application.Lock
Application("Active")=Application("Active")+1
dim this


IF REQUEST.Cookies ("CK") IS NOTHING THEN
RESPONSE.REDIRECT("LOGIN.ASPX")
ELSE
APPLICATION("CK") = REQUEST.Cookies ("CK")("UID").TOSTRING()
Application("uid") = REQUEST.Cookies("CK")("UID")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='" & "YES" &"' WHERE UNAME = '" & Application("uid") &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING
response.write("<BR>eeeeee<BR>" & Application("uid") )
Application("this") = Session.SessionID
END IF

Application.unlock
End Sub


Sub Session_OnEnd

DIM UID = Application("uid")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='" & "no" &"' WHERE UNAME = '" & UID &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING

Application.Lock
Application("Active")=Application("Active")-1
Application.unlock
end sub

</SCRIPT>
************************************************** ************
NOW KEEP IN MIND, I SET MY SESSION.TIMEOUT TO 1 MINUITE, SO I DIDN'T HAVE TO WAIT AS LONG TO SEE IF IT WORKED, YOU MAY WANT TO CHANGE THAT <b>AFTER</B> YOU TEST IT FOR YOURSELF, AND ARE SATISFIED THAT IT WORKS FOR YOU.
************************************************** ************
ALSO, IT IS IMPORTANT TO REMEMBER THAT I HAVE ONLY BEEN TEACHING MYSELF PROGRAMMING FOR A LITTLE OVER 2 WEEKS NOW, SO SOME PARTS OF MY EXAMPLE MAY NOT BE THE BEST PRACTICES, AND IF YOU DO FIND SOMETHING WRONG WITH IT, PLEASE REPLY TO THIS, WITH THE ERROR YOU FOUND, SO THAT OTHERS ARENT MISLEAD. I AM NOT IMPLYING THAT THIS IS A BULLETPROOF WAY TO DO THINGS, ALL I AM IMPLYING IS THAT IT WORKED FOR ME, AND EVEN IF IT'S A LITTLE INEFFICIENT, IT FITS MY NEEDS JUST FINE, CONSIDERING NOONE ESLE COULD EVEN GET IT TO WORK.
************************************************** ************
THANK YOU ALL FOR THE HELP AND MOST IMPORTANTLY, ALL THE LINKS TO VALUABLE REFERENCE MATERIAL ON THE WONDERFULL RESOURCE WE CALL THE NET.
-------------------------------------------
ALEX GRIM
HTTP://WWW.GRIMMUSIC.COM

[email protected]
WWW.GRIMMUSIC.COM





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Country from IP? ccc_storage Classic ASP Professional 3 June 5th, 2005 10:49 AM
find if user /ip is connected ALEX_GRIM Classic ASP Professional 8 February 7th, 2005 02:36 AM
How do i find Client IP sethumail2000 C# 0 January 27th, 2005 04:42 AM
Find Own IP akremer C# 3 September 1st, 2003 01:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.