Click here to Skip to main content
11,795,568 members (77,340 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET

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 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
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 at 12-Jul-12 6:37am
Clear and crisp! 5'ed!
Rahul Rajat Singh at 12-Jul-12 6:38am
jeyamothi at 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 at 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 at 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>

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

  Print Answers RSS
0 Maciej Los 340
1 Sergey Alexandrovich Kryukov 316
2 OriginalGriff 285
3 Abhinav S 223
4 KrunalRohit 214
0 OriginalGriff 1,797
1 Maciej Los 1,415
2 KrunalRohit 1,240
3 CPallini 840
4 ppolymorphe 808

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2015
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