Solved

FormsAuthentication.SignOut is NOT working

Posted on 2007-11-26
8
3,706 Views
Last Modified: 2013-12-16
Hi..

I am trying to create logout link. When I click on the logout, it is taking me to the logon.aspx page. that is good. But, when i press the back button, it is taking me back to the default.aspx page - it should not.

This is what I have for logout:
        public void LoginLink_OnClick(object sender, EventArgs args)
        {
            Session.Abandon();
            Session.Contents.RemoveAll();
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
        }
and in the default.aspx page - form_load:
            if (HttpContext.Current.User.Identity.IsAuthenticated == false)
            {
                FormsAuthentication.RedirectToLoginPage();
            }

I also have some code in the void Application_AuthenticateRequest(Object sender, EventArgs e)
            String cookieName = FormsAuthentication.FormsCookieName;
            HttpCookie authCookie = Context.Request.Cookies[cookieName];
            if (null == authCookie)
            {//There is no authentication cookie.
                return;
            }
0
Comment
Question by:neonlights
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:Maverick_Cool
ID: 20350526
Looks like the cookie still contains login information, hence erase it as part session out.
0
 

Author Comment

by:neonlights
ID: 20350545
how do I do that?
0
 
LVL 7

Expert Comment

by:Maverick_Cool
ID: 20350575
Try this:
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:neonlights
ID: 20350600
Thanks Maverick... but, I can still do the back button.. I put remove code in:

            Session.Abandon();
            Session.Contents.RemoveAll();
            FormsAuthentication.SignOut();
            Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
            FormsAuthentication.RedirectToLoginPage();
0
 
LVL 10

Accepted Solution

by:
Oliver Amaya earned 500 total points
ID: 20350795
Hi, it may be an issue with the browser keeping a copy of the page in cache, when you press the back button I believe the normal chain of events in a request don't get fired, try adding the following line to the top of your page_load event to ensure that the browser always asks for the page in the server:
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Open in new window

0
 
LVL 7

Expert Comment

by:Maverick_Cool
ID: 20350858
Do you have Aynonmous authentication on WebPAges check inetmgr
0
 

Author Comment

by:neonlights
ID: 20350968
Hi Joex911 - THANK YOU!....

Worked perfectly..

Thanks again.
0
 

Author Closing Comment

by:neonlights
ID: 31410992
Right on the target!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question