Hi All,
Please help me in closing browser when clicked on log out button
string strClose = "";
Page.ClientScript.RegisterStartupScript(typeof(string), "clientScript", strClose);
i used above code but its not working, please help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mukesh KumarPosted Nov 28, 2015, 3:50 AM
There are a few things you can do to make sure the user is signed out when the browser is closed, but it depends on how you're setting the FormsAuthentication cookie:
Cookieless=True.FormsAuthentication.SetAuthCookieto set Persistence tofalsewindow.unload.Cookieless=Trueapproach:This appends the cookie value to the querystring in each request. The problem with this approach is it's not very secure and it messes with SEO. If a user sends anyone the URL they're using, that person can log in as the original user (probably not what you want). As far as 'messing with SEO', it causes the same page to look different to a googlebot based on what URL is passed in. Each QueryString change makes it a new URL, and if anyone uses this for posting a link; it will dilute the search results for a given actual URL.
FormsAuthenticationTicketApproachWhen you set an Authentication cookie for the user, set Persistent to
False.If you're doing this in the
FormsAuthentication.SetAuthCookie, this is default. If you use theFormsAuthenticationTicketclass, you have to specify the cookie expiration.FormsAuthentication.SetAuthCookie()ApproachBy default, if you don't set
persistent, the authentication cookie will expire at the end of the session (when the user closes the browser).JavaScript approach:
There are no foolproof methods; all you can do is set the cookie expiration date to before now and hope the user's browser co-operates. If you really, really, really, want the cookie gone, you can always try a JavaScript approach, but that won't work if the user has JavaScript disabled.
Hope this will help you.Francis SusaimichaelPosted Nov 27, 2015, 2:00 PM