title: How can I redirect to an error page in asp.net mvc 3?
body: <p>So, I'm trying to redirect to an error page in my own AuthorizeAttribute using that:</p>
  
  <pre><code>filterContext.Result = new HttpStatusCodeResult(403);
  </code></pre>
  
  <p>In my web.config, initially i tried:</p>
  
  <pre><code>&lt;customErrors defaultRedirect="/Error" mode="On"&gt;   
      &lt;error statusCode="403" redirect="/UnAuthorize" /&gt; 
  &lt;/customErrors&gt; 
  </code></pre>
  
  <p>After i tried:</p>
  
  <pre><code>&lt;customErrors defaultRedirect="/Shared/Error" mode="On"&gt;   
      &lt;error statusCode="403" redirect="/Shared/UnAuthorize" /&gt; 
  &lt;/customErrors&gt; 
  </code></pre>
  
  <p>And after, i create a ErrorController and i tried that:</p>
  
  <pre><code>&lt;customErrors defaultRedirect="/Shared/Error" mode="On"&gt;   
      &lt;error statusCode="403" redirect="/Error/UnAuthorize" /&gt; 
  &lt;/customErrors&gt; 
  </code></pre>
  
  <p>But the browser still shows me default error page for 403, any idea?</p>
  
  <p><strong>POSSIBLE SOLUTION:</strong> Well, i saw the answers of @bobek and @Robert Levy, but i found another way, a little simpler.</p>
  
  <p>In my AuthorizeAttribute i create a propery called RedirectOnErrorTo, and in OnAuthorization method of my AuthorizeAttribute i did:</p>
  
  <pre><code>if (!string.IsNullOrEmpty(this.RedirectOnErrorTo))
  {
      filterContext.Result = new RedirectResult(this.RedirectOnErrorTo);
  }
  </code></pre>
  
  <p>So, now when i declare this attribute i choose to what path i want to redirect.</p>
  
  <p>It's not automated like i wanted using only web.config, but becomes useful. What do you think guys, it's a good way to solve this problem?</p>