SharePoint 2013 form authentication logout user credential

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.