How to close all windows upon signout?

This solution might not be the exact solution to close all open windows, but it does close all windows upon clicking sign out.

First, you need to create a sign out button on your master page. Then put this code your click event of the button.

Here is the code:

Session.Clear();

Response.Redirect("~/LoginPage.aspx");

Second, You need to create a login page. I do not need to put the code for the login page. You can do that.

Third, You need to create javascript that will open each page.

Here is the javascript:

<script type="text/javascript" language="javascript">

var winArray = new Array()

function OpenFirstPage() {

if (!winArray[0] || winArray[0].closed)

winArray[0] = window.open("FirstPage.aspx", "FirstPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");

else

winArray[0].focus();

}

function OpenSecondPage() {

if (!winArray[1] || winArray[1].closed)

winArray[1] = window.open("SecondPage.aspx", "SecondPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");

else

winArray[1].focus();

}

function OpenThirdPage() {

if (!winArray[2] || winArray[2].closed)

winArray[2] = window.open("ThirdPage.aspx", "ThirdPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");

else

winArray[2].focus();

}

function SignOut()

{

if (winArray[0] == null)

OpenFirstPage();

winArray[0].close();

if (winArray[1] == null)

OpenSecondPage();

winArray[1].close();

if (winArray[2] == null)

OpenThirdPage();

winArray[2].close();

}

</script>

Fourth, You need to add attributes to your sign out and button.

Here is the code:

this.lnkUser.Attributes.Add("onclick", "javascript:OpenFirstPage()");

this.lnkTeams.Attributes.Add("onclick", "javascript: OpenSecondPage()");

this.lnkVolunteers.Attributes.Add("onclick", "javascript: OpenThirdPage()");

this.lnkLogout.Attributes.Add("onclick", "javascript:SignOut()");

References used:

Link 1

Link 2

Link 3

Link 4

Link 5

Link 6

Link 7

Link 8

Advertisements
This entry was posted in ASP.NET 3.5, ASP.NET 3.5 And C# 3.5, ASP.NET 3.5 And JavaScript, C# 3.5, JavaScript. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s