In my custom login script I'm creating a cookie that can be read by other company web applications. The code for this is:
setCookie("Communities", "LoggedIn=true&NSContactId=" + NSContactId, ".mydomain.com");
where
public static void setCookie(string cookieName, string cookieValue, string cookieDomain)
{
HttpCookie newCookie = new HttpCookie(cookieName);
newCookie.Value = cookieValue;
newCookie.Expires = DateTime.Now.AddDays(30);
newCookie.Domain = cookieDomain;
HttpContext.Current.Response.Cookies.Add(newCookie);
}
I need to remove this custom cookie when someone logs out of SharePoint, and I'm having trouble with this.
I created a custom signout page (mylogout.aspx), and replaced the default one with this custom one, using the following:
Set-SPCustomLayoutPage -Identity SignOut -RelativePath "/_layouts/mylogout.aspx" -WebApplication "http://sp.mydomain.com"
and "mylogout.aspx" uses this code:
<%
HttpCookie CommunitiesCookie = new HttpCookie("Communities");
CommunitiesCookie.Value = null;
CommunitiesCookie.Domain = ".mydomain.com";
CommunitiesCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(CommunitiesCookie);
Response.Redirect("/_layouts/signout.aspx");
%>
I know the code is being run (I can put in a line of code to write to a log file, and it does so), but the cookie doesn't get removed. I've used this code in non-SharePoint sites before, and it works there, so I'm left assuming that something in SharePoint is stopping this from working.
Any ideas?