Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Guys,

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.


Thanks,

Hernan Cabrera
Posted

One choise is to register the visitors in a database SQLite or something simular. You could check the IP adress:
http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net[^]

and/or the host name:
http://stackoverflow.com/questions/6160991/how-to-get-client-machine-name-in-asp-net-c-sharp[^]

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 asp.net[^]
 
Share this answer
 
Comments
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.
Hello,

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



C#
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.
 System.Web.HttpContext.Current.Response.Cookies.Add(myCookie);
 return false;
}
else
{
    return true;
}
}


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

C#
void Session_End(object sender, EventArgs e)
{
}


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

What if session timeout reach? What should I do?

Thanks
Vinod Viswanath 1-Sep-12 10:23am    
Hi,

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)
{
base.OnInit(e);
if (Context.Session == null)
{
//remove cookies data
}


}
}


public partial class _Default : SessionCheck
{
//your code here
}

Hope you understood the scenario..

Thanks!!
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