How can we check if web page is open or not using vb.net??
:icon_cry:

hollystyles commented: Good humour. Cheers :) +5

Dani AI

Generated

: short answer — the server cannot magically know a browser tab is "open" unless the page itself tells the server. was right to ask for clarification; "open" usually means "user is actively connected/visible" which must be signaled by the client. Ignore the joke from — this is a protocol limitation, not a language issue.

Two practical patterns used in real apps:

  1. Heartbeat (simple, widely compatible)

    • Page JS sends a periodic ping (AJAX/fetch) to a VB.NET endpoint. The server stores a last-seen timestamp (Cache/MemoryCache/DB). Consider the user "online" when last-seen is within a threshold (e.g., 30s).
    • Use navigator.sendBeacon on unload to try to mark explicit close, but do not rely on unload for correctness.
  2. Persistent connection (more reliable)

    • Use WebSockets/SignalR so the server can detect disconnects immediately. For scaled deployments, use a backplane (Redis/SQL) so presence is shared across servers.

Example (conceptual):

// client: send heartbeat every 15s and try to notify on unload
setInterval(function(){ fetch('/Presence.asmx/Ping', {method:'POST', body: JSON.stringify({id: sessionId})}); }, 15000);
window.addEventListener('unload', function(){ navigator.sendBeacon('/Presence.asmx/Ping', JSON.stringify({id: sessionId, closing:true})); });
' server: simple WebMethod that updates HttpRuntime.Cache with DateTime.UtcNow
<System.Web.Services.WebMethod()> _
Public Shared Function Ping(sessionId As String, Optional closing As Boolean = False) As Boolean
  Dim key = "presence:" & sessionId
  If closing Then HttpRuntime.Cache.Remove(key) : Return True
  HttpRuntime.Cache.Insert(key, DateTime.UtcNow, Nothing, DateTime.UtcNow.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration)
  Return True
End Function

Cautions: unload events and background timers are unreliable (mobile and modern browsers throttle them). For production, prefer SignalR/WebSockets and a distributed store for presence.

Recommended Answers

All 2 Replies

What to you mean by "open"?

How can we check if web page is open or not using vb.net??

i usually find MY.EYES are best for this, VB.NET sucks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.