title: ASP.NET MVC - CustomeAuthorize filter action using an external website for loggin in the user
body: <p>I have a CustomeAuthorize action filter that forwards the user to signin page if user is not authenticated. I apply this filter to actions or controllers. </p>
  
  <pre><code>[CustumeAuthorize]
  public ActionResult MyAction()
  {
     //do something here
     return View();
  }
  </code></pre>
  
  <p>and the filter looks like this:</p>
  
  <pre><code>public class CustomAuthorizeAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
  
          if (!currentUserIsAuthenticated)
          {
  
              filterContext.Result =
                  new RedirectToRouteResult(
                      new RouteValueDictionary{{ "controller", "Account" },
                                                   { "action", "SignIn" },
                                                   { "returnUrl",    filterContext.HttpContext.Request.RawUrl }
                                                  });
          }
          else
          {
              base.OnActionExecuting(filterContext);
          }
      }
  }
  </code></pre>
  
  <p>Once I assign a value to filterContext.Result, after execution of filter finishes, the execution is (somehow?!) redirected to the SignIn action and MyAction does not execute. This is exactly what I want.</p>
  
  <p>Now say I want to change my CustomAuthorize to authenticate the user against an external website and not my own SignIn action so I am doing something like this:</p>
  
  <pre><code>public class CustomAuthorizeAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
  
          if (!currentUserIsAuthenticated)
          {
               filterContext.HttpContext.Response.Redirect("http://externalSite.com/login?returnUrl=" + filterContext.HttpContext.Request.RawUrl);
          }
          else
          {
              base.OnActionExecuting(filterContext);
          }
      }
  }
  </code></pre>
  
  <p><strong>My problem is</strong> that after the execution of the second version of CustomAuthorize filter is finished, execution continues to MyAction which is not what I want! How do I stop the execution of MyAction after filter in this case?</p>
  
  <p><strong>-Update-</strong> I just came across a new issue. My MVC application is in an iFrame and I want the Redirect to force the current frame as the main frame after redirection, so I am doing something like: </p>
  
  <pre><code>string url = "http://externalSite.com/login?returnUrl=" + filterContext.HttpContext.Request.RawUrl;
  filterContext.HttpContext.Response.Write("&lt;script type=\"text/javascript\"&gt;\ntop.location.href = \"" + url + "\";&lt;/script&gt;");
  </code></pre>
  
  <p>Is there a way to pass a javascript to RedirectResult()?</p>