Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

 
discard

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.