Solved

FormsAuthentication.SignOut is NOT working

Posted on 2007-11-26
8
3,658 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Accepted Solution

by:
joex911 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now