Solved

FormsAuthentication.SignOut is NOT working

Posted on 2007-11-26
8
3,675 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
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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