2

Having an issue when trying to change a cookie value. My app checks if the user is browsing with an old browser like IE8. If so, he's redirected to a specific page to inform about compatibility issues. This page contains a link with a query string to the main page.

The idea is to use a cookie with the value set to true after the first redirect (by checking if that specific query string exists), to prevent further redirections.

Current code:

HttpCookie _forceEntry = Request.Cookies["_forceEntry"];

if (_forceEntry == null)
{
    _forceEntry = new HttpCookie("_forceEntry");
    _forceEntry.Values.Add("_forceEntry", "false");
    Response.Cookies.Add(_forceEntry);
}

if (Request.QueryString["ForceOldIE"] != null)
{
    _forceEntry["_forceEntry"] = "true";
}

if (_unsupportedBrowser.Values["_unsupportedBrowser"].ToString() == "true" && _forceEntry["_forceEntry"] == "false")
    Response.Redirect("~/SupportedBrowsers/Index?applicationId=1");

This works whenever the query string exists. The cookie value is changed to true. But when I try to navigate to another page, the value is returning false again, getting me redirected again.

How come this is happening? Shouldn't the cookie value persist as true across other pages after being set on the last if?

João Colucas
  • 249
  • 1
  • 3
  • 14

0 Answers0