0

I have implemented a custom form based authentication solution. However when user click the OOTB signout button, a http 500 internal server error is thrown.

https://social.msdn.microsoft.com/Forums/sharepoint/en-US/d9d682d8-b05c-4188-9750-418e1c862fc6/sign-out-error-forms-based-authentication

http://blog.lekman.com/2012/07/resolved-sign-out-from-forms.html

i know that the issue lies with the user cookies. however im not sure where/how can i clear the user cookies programmatically, is there a way to add in code to the signout.aspx?

1
private void ExpireAllCookies()
{
    if (HttpContext.Current != null)
    {
        int cookieCount = HttpContext.Current.Request.Cookies.Count;
        for (var i = 0; i < cookieCount; i++)
        {
            var cookie = HttpContext.Current.Request.Cookies[i];
            if (cookie != null)
            {
                var cookieName = cookie.Name;
                var expiredCookie = new HttpCookie(cookieName) {Expires = DateTime.Now.AddDays(-1)};
                HttpContext.Current.Response.Cookies.Add(expiredCookie); // overwrite it
            }
        }

        // clear cookies server side
        HttpContext.Current.Request.Cookies.Clear();
    }
}
  • hi Michal, i tried adding your code to the signout.aspx by adding <script runat=server> [your code] </script> but it still didn't solve my issue – user1166085 Nov 23 '15 at 3:26
  • @user1166085 FYI, this is Server-Side not Client-side code – GoldBishop Oct 26 '17 at 18:47
0

Ctrl + F5 response for reload all scripts in your browser Ctrl + Shift + Delete open properites where you can delete all cookies from browser cache

  • i wish to do this programmatically, is there a way to add in code to the signout.aspx? – user1166085 Nov 18 '15 at 8:30
0

Try below :

private void RemoveCookiesAndSignOut()
{
    // Clear session state. 
    if (Context.Session != null)
    {
        Context.Session.Clear();
    }

    string cookieValue = string.Empty;
    if (Context.Request.Browser["supportsEmptyStringInCookieValue"] == "false")
        cookieValue = "NoCookie";

    // Clear my own cookie.
    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 cookies for 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 = new DateTime(1970, 1, 1);
        Context.Response.Cookies.Remove("MSOWebPartPage_AnonymousAccessCookie");
        Context.Response.Cookies.Add(cookiePersist);
    }

    // Sign out.
    Microsoft.IdentityModel.Web.FederatedAuthentication.SessionAuthenticationModule.SignOut();
}

Or

jQuery(function ($) {
var removedLinks = 'removedLinks'
,Options = {
expires: 7,
path: '/news'
},
c=$.cookie(removedLinks)||'#DebuggingCode'
$(c).remove();
$(".NewsHider a").click(function (e) {
e.preventDefault();
var LinkClass = '.'+ $(this).attr('id'),
removeLinksClasses=c.split(',')
$(LinkClass).remove()
removeLinksClasses.push(LinkClass)
c=removeLinksClasses.join(',') 
$.cookie(removedLinks, c, Options)
});
$('#NewsResetCookie').click(function(){
$.cookie(removedLinks,'',{expires:-1,path:'/news'})
})
});

to do this, edit the file at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\signout.aspx Modify function _spBodyOnLoad() Add code to clear cookie before window.close().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.