SharePoint – Custom Sign Out page

Developing Form Base Authentication (FBA) for Sharepoint project sometimes need big struggle, besides developing OOTB Sharepoint itself. After created custom login, I found new problem when tried to sign out from default link. It will show error page / internal server error. Caused by default page is not working properly, it signed out but doesn’t remove cookies from browser. So what I did is creating new application page, put method to clear cookies, then add a link inside default page which redirect to sign-out page.

Here is the code:

public partial class Logout : LayoutsPageBase
	protected void Page_Load(object sender, EventArgs e)
		var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
		// Clear .ASPAUTH cookie key.
		if (authCookie != null)
			var myCookie = new HttpCookie(authCookie.Name)
						{Expires = DateTime.Now.AddDays(-1)};

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

		if (iisSettingsWithFallback.UseClaimsAuthentication)
			// Clear FedAuth Cookie key
		SPUtility.Redirect(Web.ServerRelativeUrl, SPRedirectFlags.Default, Context);

Thanks for this blog. I’ve solved this problem.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s