Link to home
Start Free TrialLog in
Avatar of neonlights
neonlights

asked on

FormsAuthentication.SignOut is NOT working

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;
            }
Avatar of Maverick_Cool
Maverick_Cool
Flag of India image

Looks like the cookie still contains login information, hence erase it as part session out.
Avatar of neonlights
neonlights

ASKER

how do I do that?
Try this:
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
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();
ASKER CERTIFIED SOLUTION
Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you have Aynonmous authentication on WebPAges check inetmgr
Hi Joex911 - THANK YOU!....

Worked perfectly..

Thanks again.
Right on the target!