.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

logging out users when user opens website in two browsers or two tabs of same browser.

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net


We have the implement the following scenario in our application:

  1. We use windows authentication. User opens our website in tab1 and does some action but with out clicking on save he opens a new tab tab2 and opens the same website again.
  2. Now, if the user session in tab1 is active i need to warn users that the he is already logged on to application in some other browser and go to some log out page. But if the user session in tab1 is timed out then he must be able to continue with the website in tab2 as usual, but if he tries to do anything in tab1 he should go to session expired page.

I tried implementing it in following way.

  1. I have a hidden field in each page which will be set to unique Id using GUID.NewID().
  2. when user requests for a page the following code is executed.
  3. if (Request.Headers["Cookie"] == null)
                    //this means user is requesting hte page for first time.
                    //Generate a new GUID store it in session and also in the hidden variable on page.
                    Session["DefaultPage"] = Guid.NewGuid().ToString();
                    ((TextBox)page.FindControl("hiddenGUID")).Text = Session["DefaultPage"].ToString();
                else if (Reque

    View Complete Post

More Related Resource Links

How to make sure that user doesn't open same webpage in two different browsers or browser tabs?



We are using asp.net StateServer for asp.net session management. In our project we need to make sure that if a user is already logged in and if he is trying to acess the website from a different browser tab, we need to inform him that he is already logged in in another tab and use it instead of opening a new session. Consider the following scenarios:

1. User is logged on in tab1 and his session is still on, then user tries to logon from another tab, the browser sends the asp.net session_id cookie, In the page init i am checking if the Asp.net session Id cookie is present, if it is there i am checking if the it is a new Session (i.e. if the existing session timed out), if it is a new session then proceed with the user action else it means that the session in tab1 is still active so i am redirecting user to error page with appropriate message.

Now the problem with this approach is that, suppose session in tab1 is expired and user opens tab2 and performs some actions, now he goes back to tab1 and perform any action, i directly need to take him to log out page.

Please let me know how this can be achieved.

Is it possible to preserve viewstate when the user opens multiple browser tabs?


I want my users to be able to open multiple browser tabs and be able to switch back and forth between them.  If Viewstate is saved for each page, I should be able to do this right?



MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Creating a user friendly alias for the website path


 Hello mates,

I am hosting my ASP.NET application on a Windows 2003 Server.

To browse to my application one has to type the path :http://serverName/applicationName

I want users to only type  applicationName on the web adress area.I believe there is something to do with alias and CNAME on DNS records that can adress this.

Any help on how to go about doing this will be highly appreciated.

How Restrict and Allow user to Pages of Website.


i have 4 pages of website

2 pages are authorized to used by USER and 2 pages are restricted for user

admin can authorized to go all 4 pages


i need coding for Login window from which Admin/User Login



Forms based users being prompted for windows authentication login for My Sites photos in user lists

Here's an issue I didn't see coming for our forms based authentication users. 

We have a web application extended to an external url to handle forms based authentication for users outside of our domain. Our setup looks like this...

Internal Users/Windows Authentication - moss.domain.com
External Users/Forms Based - mossext.domain.com
My Site for Internal Users - mysites.domain.com

When our forms based users are accessing user lists, or discussion pages that display user pictures, they are getting a windows authentication login for our internal users (mysites.domain.com) who have populated their my site with personal photo.

How do we fix this? 

Separate sessions in browser tabs together with an ajax enabled web site


I want my tabs in my browser to have separate sessions. I  was told to use

<sessionState mode="InProc" cookieless="UseUri"></sessionState> in web.config

 but when I read about it here: http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=VS.100).aspx

the text says "When you configure an AJAX-enabled ASP.NET Web site, use only the default value of UseCookies for the cookieless attribute. Settings that use cookies encoded in the URL are not supported by the ASP.NET AJAX client script libraries."

I'm using Ajax so are there any ideas what I can do about this problem.

IP addresses of the users who are visiting my website



I want to know IP addresses of the users who are visiting my website.

Is it possible to know their computer names?




Automatic expiration of forms authentication when user closes the browser windows without signing ou

Dear all, can u tell me how to automatically sign out a user if he/she closes the browser window without signing out. I'm using Forms Authentication.   Thanks 

Checking SQL Server User Roles and Creating SQL Server Users using VB.NET

Hello gurus!Firstly I want to apologies if this question is out of place here.. if someone can direct me to the correct forumn great and Thanks!I have a VB.NET application which uses its own Backend Database (MSSQL Server). I need to distribute this application to sites where there will be an existing SQL Server.So I will need to Create the Database on this server. The Application includes methods for building the database on startup if not already connected to one.However the users windows logon may not have the correct permission to connect and create a Database on the Server. I have a DB Setup form in my application which asks for the Servname, Username, Password and Database name. I have catered for Windows Authentication and SQL Server Authentication within the form - the user makes the choice.Assuming they enter a Username and Password for SQL Server Athentication then I will be trying to connect using this user and create the database on the given server. The following is my outline logic:-                                                                  Create db Process                                                                             |                                                                             |                                                               Check Credentials                                                                   / 

limitate user permission to edit other users documents

i have a list where everybody uploads documents, but i want that only the user that uploaded the document can edit it or delete it, is there a simple way without workflows or code? thanks!

Map Asp.net website Roles and Users to Sharepoint website roles and users

Hi I have created an asp.net website with SQL Server based form authentication and authorization. Now, we are moving this pure asp.net website to Sharepoint 2010 website. I have developed 5 webparts for my asp.net website to migrate to Sharepoint. All these webparts are avilable for access in the same page. Now I need to implement authentication and authorization for access to these webparts in Sharepoint. I am newbie to sharepoint. Can someone provide me how can I provide authorization and authentication in Sharepoint, which should use the current SQL Server based form authentication and authorization(roles and users of my existing asp.net website) and how can I map roles and users of my existing asp.net website to Sharepoint. Please reply ASAP. Thanks & Regards Mahendra Babu

FBA users (ldap provider) don't have any user profile info when logged in.... what am I doing wrong

Sharepoint 2010, Claims authentication, FBA using ldap membership provider and role provider against Active Directory.  User profiles all imported just fine -- used the LDAP FBA provider hitting Active Directory to do so too.  whenever an FBA user logs in, it doesn't seem like sharepoint is picking up any user attributes.  targeted audiences don't work and MY SETTINGS is blank other than account and name.  If the same user logs in but through Active Directory, everything works just fine... targeted audiences, etc. Am I doing something wrong or can I not use the LDAP provider to authenticate to AD and also use the user profiles from Sharepoint?  GRRRRR.  All this to get around the Windows Authentication popup so I can customize a better looking logon experience.  Help?

How to add a user to "Debug Users" group

I want a given user to be added to "Debug Users" group. This is what the requirement is. To be very frank I am not sure where I can see this group in the computer. I tried to locate this in "computer management" -> Groups but couldn't find it. Can any body please throw some light on this. Whats the use of this group, where can i find this & how to add a user to this group?

Changing a users role with RadioButtons (User is always in single role)

So I have a set of 5 radio buttons corresponding to the roles a user can have on my website.  I have been successfully able to retreive what radio button needs to be checked for the role the user is currently in... string username = Request.QueryString["username"]; // Get Access Levels and populate radio buttons. if (Roles.IsUserInRole(username, "Banned") == true) { RadioButton4.Checked = true; } if (Roles.IsUserInRole(username, "Member") == true) { RadioButton1.Checked = true; } if (Roles.IsUserInRole(username, "FOB_Employee") == true) { RadioButton2.Checked = true; } if (Roles.IsUserInRole(username, "FOB_Administrator") == true) { RadioButton3.Checked = true; } if (Roles.IsUserInRole(username, "Webmaster") == true) { RadioButton5.Checked = true; } My problem is I do not know what to do with the actual procedure of changing the roles based on the new radio button selection.  I have tried many different methods, including using if statements to check if the user is currently in the role, remove him/her from that roll, and then add the user to the newly selected role.  It appears, from my testing, that you can not

Can I have an SQL Express database open in VS2010E along with the website? "Login failed for user ..

Hi, as the topic says..Whenever I have my database open in Visual Studio 2010 Express, I get this error:Cannot open user default database. Login failed.Login failed for user 'IIS APPPOOL\DefaultAppPool'.Cannot open user default database. Login failed.Login failed for user 'IIS APPPOOL\DefaultAppPool'.

Defaults and User Defined Types Tabs in SSMS

Hello, Just to make sure I was using all the available tools for the right purpose, I have been going through all the tabs I haven't used in SSMS. I've managed to research what they all mean but two have me a little stumped. These two tabs are: [Database]->Programmability->Defaults Quite hard to search for help on as the word default is used to explain a lot of different things! [Database]->Programmability->Types->User-Defined Types I understand what "User-Defined Table Types" and "User-Defined Date Types" are, so what goes in "User-Defined Types"? Can anyone explain what these are? Thanks very much
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend