Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FormsAuthentication.SignOut is NOT working

Posted on 2007-11-26
8
Medium Priority
?
3,737 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

824 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