Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

How can I validate if website is already open.

I want to limit connection to my website per pc.
If my website is already open in the user's pc and try to open it again from another browser then I want to just focus to the currently open browser.


Hernan Cabrera

One choise is to register the visitors in a database SQLite or something simular. You could check the IP adress:[^]

and/or the host name:[^]

Get the browser:
Detect the browser using ASP.NET and C#[^]

If those two dosnt work I dont really know what you should do. I dont really see what the point is though....

BTW: Mac Adress it more troublesome:
How to get Mac Address of Client Machine in[^]
Share this answer
Hernan K. Cabrera 29-Aug-12 18:19pm    
Hi Kenneth,

I don't want my user to open my web page twice simultaneously in his pc that is why I want to detect if the web page is already open.

Better approach is to create Cookies on clients, And check cookie every time. Refer following code snippet.

public bool IsInstanceAlreadyExist()


 if (null == System.Web.HttpContext.Current.Request.Cookies["InstanceExist"])

 HttpCookie myCookie = new HttpCookie("InstanceExist")

 // Set the cookie value.
 myCookie.Value = "True";
 // Add the cookie.
 return false;
    return true;

And clear the cookie on Session to handle browser close issues.

void Session_End(object sender, EventArgs e)

Share this answer
Hernan K. Cabrera 30-Aug-12 11:02am    
Hi Vinod,

What if session timeout reach? What should I do?

Vinod Viswanath 1-Sep-12 10:23am    

Create a base class and check for session is null or Session.IsNewSession then remove the cookie cariable

public class SessionCheck: System.Web.UI.Page
override protected void OnInit(EventArgs e)
if (Context.Session == null)
//remove cookies data


public partial class _Default : SessionCheck
//your code here

Hope you understood the scenario..

Hi Kenneth and Vinod,

I've tried to use variable from global.asax and its working now.

for each user that login, I concatenate to a variable from global.asax but before
that I use instr to validate if the user is in the variable.

thanks to both of you.

Hernan Cabrera
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900