Friday, January 31, 2014

sharepoint 2010 foundation signout issue

Hi Karunanithi,


Below code will clear out all the cookies. Although I have only used this code for Claims Based mode, try and see if it works for you as well:



protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

ClientScriptManager cm = Page.ClientScript;

String ulsScript = "function ULSLogout(){var o=new Object;o.ULSTeamName=\"Microsoft SharePoint Foundation\";o.ULSFileName=\"LogOut.aspx\";return o;}";
cm.RegisterClientScriptBlock(this.GetType(), "UlSLogout", ulsScript, true);

String closeBrowser = "function _spBodyOnLoad() {ULSLogout:; try { document.execCommand(\"ClearAuthenticationCache\"); } catch (e) { } window.close(); }";
cm.RegisterStartupScript(this.GetType(), "CloseBrowser", closeBrowser, true);

ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseBrowser", "_spBodyOnLoad();", true);
RemoveCookiesAndRedirect();
}

private void RemoveCookiesAndRedirect()
{

if (this.Context.Session != null)
{
this.Context.Session.Clear();
}
string str = string.Empty;

if (this.Context.Request.Browser[SupportsEmptyStringInCookieValue] == "false")
{
str = "NoCookie";
}

HttpCookie cookie = this.Context.Request.Cookies[CookieWssKeepSessionAuthenticated];

if (cookie != null)
{
cookie.Value = str;
this.Context.Response.Cookies.Remove(CookieWssKeepSessionAuthenticated);
this.Context.Response.Cookies.Add(cookie);
}

HttpCookie cookie2 = this.Context.Request.Cookies[CookieWssKeepAuthenticated];

if (cookie2 != null)
{
cookie2.Value = str;
cookie2.Expires = new DateTime(1970, 1, 1);
this.Context.Response.Cookies.Remove(CookieWssKeepAuthenticated);
this.Context.Response.Cookies.Add(cookie2);
}

SPIisSettings iisSettingsWithFallback = SPsite.WebApplication.GetIisSettingsWithFallback(SPsite.Zone);

if (iisSettingsWithFallback.UseClaimsAuthentication)
{
FederatedAuthentication.SessionAuthenticationModule.SignOut();
int num = 0;
using (IEnumerator<SPAuthenticationProvider> enumerator = iisSettingsWithFallback.ClaimsAuthenticationProviders.GetEnumerator())
{
while (enumerator.MoveNext())
{
SPAuthenticationProvider current = enumerator.Current;
num++;
}
}

if ((num != 1) || !iisSettingsWithFallback.UseWindowsIntegratedAuthentication)
{

SPUtility.Redirect(BaseWebpart.FBA_Next_Step, SPRedirectFlags.Default, this.Context);
}
}
else if (AuthenticationMode.Forms == SPSecurity.AuthenticationMode)
{
FormsAuthentication.SignOut();
SPUtility.Redirect(BaseWebpart.FBA_Next_Step, SPRedirectFlags.Default, this.Context);
}
else if (AuthenticationMode.Windows != SPSecurity.AuthenticationMode)
{
throw new SPException();
}

SPUtility.Redirect("/_layouts/signout.aspx", SPRedirectFlags.DoNotEncodeUrl, this.Context);
}

Cheers,

Vincent


No comments:

Post a Comment