Problems setting a cookie that already exists



Hello,

I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value.

For example (this is running in a DLL, which is why I use HttpContext)...

HttpCookie cookie = new HttpCookie("fred", "ferret");
DateTime expiryDate = DateTime.Now.AddMonths(1);
cookie.Expires = expiryDate;
HttpContext.Current.Response.Cookies.Add(cookie);

works fine if the cookie "fred" does not already exist, but if it does, then it is not updated to have the new value.

How do I handle this? I tried...

HttpContext.Current.Response.Cookies["fred"] = cookie;

but that didn't do anything either. Either way, the old value remains in the cookie.

Any advice appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)
.



Relevant Pages

  • Re: Getting cookies of previous page
    ... to me as .dll files to include in the project. ... Project A sets its cookie name in its web.config and Project B in its ... If I have understood what you are doing, you are calling a DLL that retrieves the name from its .config file. ... Another alternative would be to create a folder below the main folder of projectB, create a second web.config in that folder, copy into it the relevant portion of the web.config in projectA, and run the page that needs the cookie name in that folder. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Accessing cookies from DLL
    ... this dll contains a CompositeControl. ... Nathan ... write to a directory (after I set permissions). ... to write a cookie you use Response.Cookies.... ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Whats better, a hidden form field or viewstate?
    ... uses a Cookie to track the SessionId for the client:) ... Alan Silver. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Problems setting a cookie that already exists
    ... two separate values for "fred", and the code was only able to read the first. ... I'm still at a loss as to how to update a cookie value when it already exists. ... Alan Silver. ...
    (microsoft.public.dotnet.framework.aspnet)