Solved

Why not Request.IsClientConnected?

Posted on 2004-09-19
7
942 Views
Last Modified: 2011-10-03
Hi Experts,

I have seen following code in a few tutorials
If response.IsClientConnected=true then
but there is not good explanation for that and I got questions:
1. What does disconnected mean?
2. Is a client a session?
3. If we got a few client, when we know response.IsClientConnected = true, how to know which session/client is connected?
4. Why not Request.IsClientConnected?
0
Comment
Question by:daveask
  • 4
  • 2
7 Comments
 
LVL 14

Assisted Solution

by:huji
huji earned 70 total points
ID: 12095971
As far as I know, there are some cases in which the client is disconnected (for example by closing the browser window) but the server does not sense it. That is, the server continues processing the codes which takes resources and time. So for huge processings you can ensure the client to be still connected by that piece of code, and stop the rest of the code, if he is disconnected.
An example is, you can put some lines in golbal.asa file under Session_OnEnd function, and hope that they are run when the client disconnects from your site, any way, but in reality, this may be done only sometimes.

Wish I can help
Huji
0
 

Author Comment

by:daveask
ID: 12096569
Thank you.
So,
1. the server cannot accurately know when the client disconnects,
2. the server can delect if a client still disconnected or not by send something to the client, that is why it uses response instead of request,
3. put response.IsClientConnected in Session_OnEnd function so that after a session timeout interval we know this session(client) is really disconnected or not,
4. it is no use to put response.IsClientConnected in another places (other than Session_OnEnd or Session_OnStart), because we wont know which client we are checking.

Am I right?
0
 
LVL 14

Expert Comment

by:huji
ID: 12099550
Part 1 and 2 are correct.
Part 3 is not. Session_OnEnd is run when the server knows that the client is disconnected, so untill it does not know that, it will not run that function, and IsClientConnected is not called.
Part 4 is not correct again. You can use IsClientConnected in many other places, and I give you an example:
When a user makes arequest which needs lots of processing and connecting to several databases (which may take as much as 20 seconds on your server for example), you can check if he is still connected, in the middle of the processing code; if not, you can simply cancel the rest of the processing to free some CPU for other online users.
Wish I can help
Huji
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:daveask
ID: 12100293
Thank you and I am glad that I got two of four are correct :)

>Session_OnEnd is run when the server knows that the client is disconnected
It seems to me that Session_OnEnd is fired when timeout instead when the client closes his browser!

>You can use IsClientConnected in many other places
If we have a few clients, when we find response.IsClientConnected = False, how to know which client disconnected?
0
 
LVL 14

Expert Comment

by:huji
ID: 12100758
No. The session is ended when it is ENDED any ways! You specify session timeout as 30 minutes, and it means that if the user has his window open and remains idle (no clicks, no other types of reconnection to your server) then the session is ended after 30 minutes, but if the user refreshes the page 29 miinutes 55 seconds after the last connection to your site, the session is renewed again, and another 30 minutes will be needed for OnEnd to happen.
Passing the timout is only one way to finish sessions. Another situation is when the server understands that the user has closed the browser window related to that session number, but this is not detected by servers as often as it happens.
Second and more iportant point: when Reponse.IsClientConnected is Flase, it means that THIS session is disconnected! and the ID of this session variable is stored in Session.SessionID (read-only) property. You can not know which username in your database is disconnected, unless you store the sessionID when the user is authenticated in the database.
Don't hesitate to ask questions.
Wish I can help
Huji
0
 
LVL 15

Accepted Solution

by:
joeposter649 earned 30 total points
ID: 12102893
I think huji covered a lot here but you should realize that, just like the rest of the response methods, IsClientConnected can only be used once the browser requests a page.  Nothing in asp can initiate contact with the client.

This link might help too.
http://devguru.com/Technologies/asp/quickref/response_isclientconnect.html
0
 
LVL 14

Expert Comment

by:huji
ID: 12103551
Well joeposter649 noted a good point. As IsClientConnected is a reposnse method, it can only be called when a RESPONSE is being made. So you can call it several times after a response STARTs and before it is ENDed.
I suppose that your question is answered, am I right daveask?

Wish I can help
Huji
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question