Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
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 12-Jul-12 0:48am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
jeyamothi at 12-Jul-12 6:27am
   
even though i didn't use the logout/signout page in my project
Prasad_Kulkarni at 12-Jul-12 7:13am
   
Yes. It will work.
Rate this: bad
good
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.
  Permalink  
Comments
Vani Kulkarni at 12-Jul-12 6:37am
   
Clear and crisp! 5'ed!
Rahul Rajat Singh at 12-Jul-12 6:38am
   
thanks.
jeyamothi at 13-Jul-12 2:08am
   
Thanks.
 
I tried but i throws error page not moved to login page how can i achieve this. Help me for this
jeyamothi at 16-Jul-12 7:38am
   
if i select next page it throws error
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is for Session store a value
Session["Name"]=value;
 

 
this is for session close.
 
Session.Remove("Name");
  Permalink  
Comments
jeyamothi at 12-Jul-12 6:22am
   
already i give the
session.clear()
session.abandon()
session.remove(session.sessionID)
formsauthentication.signout()
 
i give these in session_end() in global.asax page.
 
but these are not working properly
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thanks,

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 {
            //redirected
            clicked = false;
        }
    }
 
    function bodyUnload() {
        if (clicked == false)//browser is closed
        {
            //var request = GetRequest();

            //location.href = 'LogOut.aspx';
            var request = GetRequest();
 
            request.open("GET", "LogOut.aspx", true);
            request.send();
        }
    }
    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>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2014
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