Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

 
Share this answer
 
Comments
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.
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:
C#
FormsAuthentication.SetAuthCookie(username, true);

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

C#
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.
 
Share this answer
 
Comments
Vani Kulkarni 12-Jul-12 6:37am    
Clear and crisp! 5'ed!
Rahul Rajat Singh 12-Jul-12 6:38am    
thanks.
jeyamothi 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 16-Jul-12 7:38am    
if i select next page it throws error
This is for Session store a value
Session["Name"]=value;



this is for session close.

Session.Remove("Name");
 
Share this answer
 
Comments
jeyamothi 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
Thanks,

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

Finally i got a solution

C#
<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>
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900