Click here to Skip to main content
15,921,382 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application and in the same I have logged in successfully. Then I would need to restrict the user to open a new tab with same url successfully.
i have used to developing in ASP.NET WITH C#,

What I have tried:

I am using the browser IE 11.

Session is active across different tabs of the same browser.
Posted
Updated 16-Oct-18 4:23am

That's a normal behavior as Session is based on the browser instance and all the tab within the instance.In addition, Sessions are stored in the server. A server doesn't know anything about client browser tabs and Windows.

Give the following discussions a read on how to get around this:

How to prevent multiple browser windows from sharing the same session in asp.net - Stack Overflow[^]
.net - Way around ASP.NET session being shared across multiple tab windows - Stack Overflow[^]
 
Share this answer
 
Session is a server side abstract based on an instance of a browser.

Tabs are fenced off from one another for security reasons, and the information is neither visible to other tabs nor available to the server.

What can be done is to utilize javascript's "window.name" property. It was designed more for opening new windows/tabs but by assigning a name to it after the connection is made. You would need to utilize then to validate the window.name before displaying content.
It has been a few years since I have worked with this and I unfortunately do no remember the code I had used.

Here is a Proof-of-Concept which does work in IE- running this from a local file will generate a script warning though.

HTML
<html>
	<head>
		<title>Test Window Name</title>
		<script type ="text/javascript">window.name="MyWindowsName";</script>
	</head>
	<body>
		<h1>
			The name for this window is:
			<script type ="text/javascript">document.write(window.name);</script>
		</h1>
	</body>
</html>
 
Share this answer
 
v2
Comments
ranio 17-Oct-18 8:11am    
we are using IE Browser. window.name won't work naa.
MadMyche 17-Oct-18 9:37am    
If it fails for you in IE, that would be a setting within your instance of IE. Running it from a desktop HTML file I do get a script warning due to it being local. I have updated my answer with proof-of-concept code

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