Skip to content

Commit 0a992d5

Browse files
Cookie expiration fix (#10626) (#10627)
* Fix * Fixed tests
1 parent bdf9d2e commit 0a992d5

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/NuGetGallery/Infrastructure/CookieTempDataProvider.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ protected virtual IDictionary<string, object> LoadTempData(ControllerContext con
9494
//silently ignore incorrect cookie values
9595
}
9696

97-
cookie.Expires = DateTime.MinValue;
98-
cookie.Value = String.Empty;
97+
if (_httpContext.Response != null && _httpContext.Response.Cookies != null)
98+
{
99+
var responseCookie = _httpContext.Response.Cookies.Get(TempDataCookieKey);
100+
if (responseCookie != null)
101+
{
102+
responseCookie.Expires = DateTime.MinValue;
103+
responseCookie.Value = String.Empty;
104+
}
105+
}
106+
99107
return dictionary;
100108
}
101109

tests/NuGetGallery.Facts/Infrastructure/CookieTempDataProviderFacts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public void WithInitialStateAndNoValuesClearsCookie()
178178
cookie["message"] = "clear";
179179
var httpContext = new Mock<HttpContextBase>();
180180
httpContext.Setup(c => c.Request.Cookies).Returns(cookies);
181+
httpContext.Setup(c => c.Response.Cookies).Returns(cookies);
181182
ITempDataProvider provider = new CookieTempDataProvider(httpContext.Object);
182183
var controllerContext = new ControllerContext();
183184

0 commit comments

Comments
 (0)