SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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, "");


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;

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 ""

and "mylogout.aspx" uses this code:

HttpCookie CommunitiesCookie = new HttpCookie("Communities");
CommunitiesCookie.Value = null;
CommunitiesCookie.Domain = "";
CommunitiesCookie.Expires = DateTime.Now.AddDays(-1);

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?

share|improve this question

Have you used a tool like Fiddler to view the HTTP traffic and the requests the browser is making? It might be worth checking to see if the browser is requesting /_layouts/signout.aspx and redirecting back to the login page and reauthenticating. What type of security do you have on signout.aspx vs mylogout.aspx?

share|improve this answer
I've not forgotten about this question, I've just had zero time to look at it recently. I do use Fiddler, but I didn't notice that there was any odd redirecting going on. signout.aspx is the ootb page, so I'm not really sure what security is in use, but being in the _layouts folder I suspect you have to be signed in initially to use it, though no special permissions. my custom logout.aspx has no special permissions added via roles/groups, etc but is still in the _layouts folder, so it's quite possible that the user is being re-signed in, as you suggest. – QMKevin Nov 9 '11 at 21:24
... However, the main issue of removing custom cookies shouldn't be impacted by this – QMKevin Nov 9 '11 at 21:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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