title: OnCacheAuthorization override
body: <p>I would like to write my own <code>OnCacheAuthorization</code> method for asp.net mvc, so I would control the user access to the site.</p>
  
  <p>I wrote my own logging system, so that after you log in you have to enter some more data until the account is authorized (I control this through a varibale). So if a user doesn't finish the the procedure, he cannot visit other pages on the site.</p>
  
  <p>I wrote the following method:</p>
  
  <pre><code>public override void OnAuthorization(AuthorizationContext filterContext)
  {
      base.OnAuthorization(filterContext);
  
  
      var httpContext = filterContext.HttpContext;
      String culture = HttpContext.Current.Session["Culture"].ToString();
      var identity = httpContext.User.Identity;
      MembershipUser userMembership = Membership.GetUser(identity.Name);
      Guid userId = new Guid(userMembership.ProviderUserKey.ToString());
      String redirectUrl = "~/" + culture + "/Error/UserRegistrationNotFinished";
      httpContext.Request.Url.ToString();
      filterContext.Result = new EmptyResult();
  
      if ((!userMembership.IsApproved) &amp;&amp; AuthorizeCore( filterContext.HttpContext ))
      {
          filterContext.HttpContext.Response.Redirect(redirectUrl, true);
      }
      else
      {
          filterContext.HttpContext.Response.Redirect(filterContext.RequestContext.HttpContext.Request.Url.ToString(),true); 
      }
  }
  </code></pre>
  
  <p>This method works. If the user did not finish his login procedure, he is correctly rerouted to <code>UserRegistrationNotFinished</code> page. The problem is that if the login procedure is finished, the method doesn't let him go to the page he entered in the URL. I only get a blank page and the method loops.</p>
  
  <p>How can I write this method, that it will work for approved users as well?</p>
  
  <p>Regards,</p>