Experiencing really weird behavior on a site I maintain, https://conservationx.com/
1) Global.asax Session_Start
, simply checks for a cookie of a specific name (visitor
) and if not present, we issue one.
protected void Session_Start()
{
var req = HttpContext.Current.Request;
var cookie = request.Cookies["visitor"];
if (cookie == null)
{
var cookie = new HttpCookie("visitor", sguid);
cookie.Shareable = false; // Do not store in outputcache
cookie.Expires = DateTime.UtcNow.AddYears(1);
response.SetCookie(cookie);
2) In local Debug, I can visit and step into it just fine, first request - Incognito window consistently gets me Set-Cookie header on first request.
3) Once deployed, I will never, ever see that Cookie issued on first request. I consistently see it on second request.
4) In addition to seeing Set-Cookie header not appear until the second request in DevTools Network tab, I've also added logging to the Session_Start body, and wrapped it all in try/catch, logging any exceptions. That likewise consistently fails to fire on first visit. This particular site checks if you're logged in once the page is done loading, with a call to /account/navaccountinfo - fresh browsers/Incognito windows will always fail to get a cookie set landing on any page on the site, then see the cookie finally set on that secondary load, and sure enough our logs are filled with cookies being set on the request to that secondary request URL.
Is this a known issue with deploying ASP.Net MVC to IIS 7.5? We are using OWIN with Identity Framework if that has any impact?
Speculating, I wonder if this is related:
OutputCache VaryByCustom cookie value
I set cookie.Shareable = false
because the visitor Id is meant to be unique per browser. Can't be giving it out to multiple people via the Server's OutputCache
. The initial page visited, like / or /about, has an OutputCacheAttribute
set and is visited via GET. The followup, /account/navaccountinfo, is visited via POST, and so, obviously never cached. So I wonder if this is actually a bad interaction between OutputCache
and cookie.Shareable = false
.