title: Is it possible to use RedirectToAction() inside a custom AuthorizeAttribute class?
body: <p>Using ASP.Net MVC 2, is there any way to use the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction.aspx" rel="noreferrer">RedirectToAction()</a> method of the <a href="http://msdn.microsoft.com/en-us/library/dd505093%28v=VS.90%29.aspx" rel="noreferrer">Controller</a> class inside a class that is based on the <code>AuthorizeAttribute</code> class?</p>
  
  <pre><code>public class CustomAttribute : AuthorizeAttribute {
      protected override bool AuthorizeCore(HttpContextBase context) {
          // Custom authentication goes here
          return false;
      }
  
      public override void OnAuthorization(AuthorizationContext context) {
          base.OnAuthorization(context);
  
          // This would be my ideal result
          context.Result = RedirectToAction("Action", "Controller");
      }
  }
  </code></pre>
  
  <p>I'm looking for a way to re-direct the user to a specific controller / action when they fail the authentication instead of returning them to the login page. Is it possible to have the re-direct URL generated for that controller / action and then use <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.redirectresult.aspx" rel="noreferrer">RedirectResult()</a>? I'm trying to avoid the temptation to just hard-code the URL.</p>