views:

126

answers:

1

My application at mysubdomain.mydomain.com needs to set a cookie that contains some user session information.

They log in at a https page. We authenticate them and set some session info in a cookie.

We do this in a helper library that takes in the controller context

contextBase.Response.Cookies[CookiePayload.CookieName].Value = encryptedTicket;                       
contextBase.Response.Cookies[CookiePayload.CookieName].Expires = cookieExpires;
contextBase.Response.Cookies[CookiePayload.CookieName].Domain= ConfigHelper.CookieDomain;
contextBase.Response.Cookies[CookiePayload.CookieName].HttpOnly=true;

We do a quick redirect in the controller (to a non https page):

this.ControllerContext.HttpContext.Response.Redirect(redirectTo, false);
return null;

The cookie appears in the response (according to firebug's net tab).

But neither fireforx nor ie send the cookie on subsequent gets.

We are setting the cookie domain to mydomain.com even though the site is mysubdomain.mydomain.com. Skipping the redirect command has no effect, nor does changing the cookie value.

I'm baffled. Thanks for any suggestions.

+1  A: 

Try explicitly setting the Secure flag to false if this cookie needs to be sent over http:

var cookie = new HttpCookie(CookiePayload.CookieName, encryptedTicket)
{
    HttpOnly = true,
    Domain = ConfigHelper.CookieDomain,
    Secure = false,
    Expires = cookieExpires
};
Response.SetCookie(cookie);
Darin Dimitrov
That seems to have done it. It seems that ASP was setting it to secure by default because the context was an https request. Thanks!
brian b