Click here to Skip to main content
13,048,584 members (90,934 online)
Rate this:
Please Sign up or sign in to vote.
See more:

In my project i am using Forms Authentication and session but when i close the browser it doesn't expire the session and authentication values.

can any one help me?
Posted 11-Jul-12 23:48pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

jeyamothi 12-Jul-12 6:27am
even though i didn't use the logout/signout page in my project
Prasad_Kulkarni 12-Jul-12 7:13am
Yes. It will work.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

The only reason for that happening could be that the authentication ticket(cookie) that you must be creating is persistent. you should create this cookie as non-persistent and this problem will not come.
look at this article here: Understanding and Implementing ASP.NET Custom Forms Authentication[^]

What you must be doing is:
FormsAuthentication.SetAuthCookie(username, true);

where the true specifies the persistant mode. so do not create a persisitant cookie. create non-persistant as

FormsAuthentication.SetAuthCookie(username, false);

I hope this will give you some pointers. if od doesnt help let know what you found at your end and I will try to see what else could be the problem.
Vani Kulkarni 12-Jul-12 6:37am
Clear and crisp! 5'ed!
Rahul Rajat Singh 12-Jul-12 6:38am
jeyamothi 13-Jul-12 2:08am

I tried but i throws error page not moved to login page how can i achieve this. Help me for this
jeyamothi 16-Jul-12 7:38am
if i select next page it throws error
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is for Session store a value

this is for session close.

jeyamothi 12-Jul-12 6:22am
already i give the

i give these in session_end() in global.asax page.

but these are not working properly
Rate this: bad
Please Sign up or sign in to vote.

Solution 4


Actually i want to expire the session at the time of browser close.

Finally i got a solution

<script language=""javascript"" type=""text/javascript"><br" mode="hold" />    //<![CDATA[
    var clicked = false;
    function CheckBrowser() {
        if (clicked == false) {
            //Browser closed
        else {
            clicked = false;
    function bodyUnload() {
        if (clicked == false)//browser is closed
            //var request = GetRequest();
            //location.href = 'LogOut.aspx';
            var request = GetRequest();
  "GET", "LogOut.aspx", true);
    function GetRequest() {
        var request = null;
        if (window.XMLHttpRequest) {
            //incase of IE7,FF, Opera and Safari browser
            request = new XMLHttpRequest();
        else {
            //for old browser like IE 6.x and IE 5.x
            request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
        return request;


<body onunload="bodyUnload();" onclick="clicked=true;">
    <form id="form1" runat="server"></form></body>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100