Find a sign out method for Sharepoint 2013 form authentication on the Internet, which is verified and valid. The method is as follows:
Private voidremovecookiesandsignout ()
{
// Clear sessionstate.
If (context. session! = NULL)
{
Context. session. Clear ();
}
String cookievalue = string. empty;
If (context. Request. browser ["supportsemptystringincookievalue"] = "false ")
Cookievalue = "nocookie ";
// Clear my owncookie.
Httpcookie cookiewinsignin = context. Request. Cookies ["morpheus_windowssignedin"];
If (cookiewinsignin! = NULL)
{
Cookiewinsignin. value = cookievalue;
Context. response. Cookies. Remove ("morpheus_windowssignedin ");
Context. response. Cookies. Add (cookiewinsignin );
}
// Remove cookiesfor authentication.
Httpcookie cookiesession = context. Request. Cookies ["wss_keepsessionauthenticated"];
If (cookiesession! = NULL)
{
Cookiesession. value = cookievalue;
Context. response. Cookies. Remove ("wss_keepsessionauthenticated ");
Context. response. Cookies. Add (cookiesession );
}
Httpcookie cookiepersist = context. Request. Cookies ["msowebpartpage_anonymousaccesscookie"];
If (cookiepersist! = NULL)
{
Cookiepersist. value = cookievalue;
Cookiepersist. expires = newdatetime (1970, 1, 1 );
Context. response. Cookies. Remove ("msowebpartpage_anonymousaccesscookie ");
Context. response. Cookies. Add (cookiepersist );
}
// Sign out.
Microsoft. identitymodel. Web. federatedauthentication. sessionauthenticationmodule. signout ();
}
You need to reference the following dll:
C: \ windows \ Microsoft. NET \ Assembly \ gac_msil \ Microsoft. Sharepoint. identitymodel \ v4.0 _ 15.0.0.0 _ 71e9bce111e9429c \ microsoft. Sharepoint. identitymodel. dll
C: \ Program Files (x86) \ reference assemblies \ Microsoft \ framework \. netframework \ v4.5 \ system. identitymodel. dll
C: \ Program Files \ reference assemblies \ Microsoft \ Windows identity Foundation \ v3.5 \ microsoft. identitymodel. dll
Page inheritanceIdentitymodelsigninpagebaseClass.