Single SignOut registration problem: FormsAuthentication.SignOut () does not work

I used the Single Sign-on demo from: http://www.codeproject.com/KB/aspnet/SingleSignon.aspx

And I add the SignOut function for this demo, but I found a problem:

when I set cookie.Domain, FormsAuthentication.SignOut () does not work, and the cookie cannot be cleared.

If cookie was not set cookie.Domain, FormsAuthentication.SignOut () works.

I used C # asp.net.

And can someone tell me some simple and practical Single Sign-On and Single Sign-Off solutions using asp.net?

+6
authentication
source share
3 answers

If you use authentication for the same domain and subdomain, try adding the domain name to web.config instead of adding the domain via code. you don’t have to encode anything if you use this entry in web.config

<authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" timeout="2880" domain="abc.com"/> </authentication> 

This entry tells the asp.net engine that an authentication cookie will be used for all abc.com subdomains. Try using this and see if it works.

+4
source share

This worked for me:

In the Logout event / method for each site, use the Cookies collection in the Request object and delete the corresponding cookies, as shown below:

 enter code hereHttpCookie cookie = Request.Cookies.Get(".CommonCookieName"); cookie.Expires = DateTime.Now.AddDays(-1); HttpContext.Current.Response.Cookies.Add(cookie); 

If all sites in SSO use the same cookie, then this is simple as described above. If several or every site participating in SSO uses its own cookie / user name for the same subject (person), then you need to delete all cookies. (perhaps create a central location by displaying usernames and cookies on each site in the SSO host collection.

+1
source share

It works for me

 public virtual ActionResult LogOff() { FormsAuthentication.SignOut(); foreach (var cookie in Request.Cookies.AllKeys) { Request.Cookies.Remove(cookie); } foreach (var cookie in Response.Cookies.AllKeys) { Response.Cookies.Remove(cookie); } return RedirectToAction(MVC.Home.Index()); } 
0
source share

All Articles