首页 > 代码库 > sharepoint 2013 Form认证 注销用户凭证

sharepoint 2013 Form认证 注销用户凭证

在网上找到一个关于sharepoint 2013 Form表单认证的sign out 方法,经过验证,有效。方法如下:

private voidRemoveCookiesAndSignOut()

        {

            // Clear sessionstate.

            if (Context.Session !=null)

            {

                Context.Session.Clear();

            }

            string cookieValue =http://www.mamicode.com/string.Empty;

            if(Context.Request.Browser["supportsEmptyStringInCookieValue"] == "false")

                cookieValue = http://www.mamicode.com/"NoCookie";

            // Clear my owncookie.

            HttpCookie cookieWinSignIn =Context.Request.Cookies["Morpheus_WindowsSignedIn"];

            if (cookieWinSignIn !=null)

            {

                cookieWinSignIn.Value =http://www.mamicode.com/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 =http://www.mamicode.com/cookieValue;

                Context.Response.Cookies.Remove("WSS_KeepSessionAuthenticated");

               Context.Response.Cookies.Add(cookieSession);

            }

 

            HttpCookie cookiePersist =Context.Request.Cookies["MSOWebPartPage_AnonymousAccessCookie"];

            if (cookiePersist !=null)

            {

                cookiePersist.Value =http://www.mamicode.com/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();

        }

需要引用以下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

页面继承IdentityModelSignInPageBase类。