title: Redirect inside the constructor
body: <p>Let's say I have a <code>Currency</code> cookie, it should be either <code>USD</code> or <code>GBP</code>. If someone manually change it to for example <code>RUB</code>, it will revert back to <code>USD</code>.</p>
  
  <p>To achieve this, I created <code>BaseController</code> class to inherits <code>System.Web.MVC.Controller</code>, then every controller in my project will inherits <code>BaseController</code>, inside <code>BaseController</code> constructor I call <code>CheckcookieValidity()</code> method. Code below :</p>
  
  <pre><code>public class BaseController : Controller
  {
        public BaseController()
        {
             If (CheckCookieValidity() == false)
             {
                  SetDefaultCookie();
             }
        }
  }
  
  public void SetDefaultCookies()
  {
      var curr = new HttpCookie("curr");
      curr.Value = "USD";
      curr.Expires = DateTime.UtcNow.AddDays(2);
      HttpContext.Current.Response.Cookies.Set(curr);
  }
  </code></pre>
  
  <p>I have some problem with this, if <code>SetDefaultCookie()</code> is called, the cookie doesn't change until the next page so</p>
  
  <ol>
  <li>Is it possible to redirect/refresh page inside constructor? </li>
  <li>Is this an acceptable way to check cookie validity? I know this question can be categorized as opinionated, but I need to know if there's a better way to achieve this.</li>
  </ol>
  
  <p>Any help will be appreciated and apologize for bad english.</p>
  
  <p>ANSWER :</p>
  
  <pre><code>public override void OnActionExecuting(ActionExecutingContext filterContext)
  {
      base.OnActionExecuting(filterContext);
  
      if (CheckCookiesValidity() == false) {
          SetDefaultCookies();
  
          RouteValueDictionary route = new RouteValueDictionary(new {
              Controller = "Home",
              Action = "Index"
          });
  
          filterContext.Result = new RedirectToRouteResult(route);
          return;
      }
  }
  </code></pre>