Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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:29 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 OUT IF USER IS CONNECTED

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.

GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
__________________
---------------------------
A Black sheep moves easy in the darkness.
GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old February 2nd, 2005, 04:39 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

hey! right there! ok if you can tell me how wrox is telling their page to postpone a response.redirect after you make a post, i can do this! you ever notice that? when you post something, it shows you a confirmation page for about 2 secs, then redirects you back to your posted comment. there HAS to be a timer associated with asp!

GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 12:27 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

The below code redirects the user to a different page after 3 seconds


<%
InitialTime = Timer()
CurrentTime = Timer()
ElapsedTime = CurrentTime - InitialTime

do while ElapsedTime < 3
  ElapsedTime = Timer() - InitialTime
loop

Response.Redirect "destinationpage.asp"

%>


Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 3rd, 2005, 12:55 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

hello this is a classic ASP forum !!! and my response was also for classic ASP only.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 3rd, 2005, 05:10 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

good example, and thanks. but are you saying that I couldn't use it in an aspx file?

GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 05:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

You can use that example in aspx also.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 3rd, 2005, 06:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

or you can do it with plain old HTML:

<META HTTP-EQUIV="Refresh" CONTENT="10;URL=http://p2p.wrox.com/"> goes to the url after 10 secs
 
Old February 3rd, 2005, 02:15 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

hey, that's a great way to save code. thanks.

GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 03:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:The below code redirects the user to a different page after 3 seconds
Well it does, but it's not useful. What it does is lock up the server (probably consuming up to 100% processor capacity) for three seconds before it redirects the page.
There is no way to display a message as is done in the Wrox forum when you make a post.

Besides using JavaScript, I think the solution provided by pgtips is the only sensible thing to use.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 4th, 2005, 12:52 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

GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM





Similar Threads
Thread Thread Starter Forum Replies Last Post
find user is logout sanjeev jha Classic ASP Professional 0 December 8th, 2007 06:36 AM
I can't find User Id and password for Chapter 6 jellyjune BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 September 21st, 2007 02:39 PM
find if user /ip is connected ALEX_GRIM Classic ASP Professional 8 February 7th, 2005 02:36 AM
find if a user/ ip is connected ALEX_GRIM ASP.NET 1.0 and 1.1 Professional 6 February 4th, 2005 12:53 AM
I can't find bugs in my Login function. (User.cs) kaz VS.NET 2002/2003 5 December 7th, 2003 05:46 AM





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