Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since your filter is executed multiple times until you get a too many requests error, the problem is probably in how you have registered the filter.</p> <p>A filter is applied globally by using:</p> <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new &lt;YourFilter&gt;); } </code></pre> <p>However, this also means that your filter is applied to your <code>Error</code> controller. Your <code>Error</code> controller will detect your server is down and then redirect to itself. </p> <p>You can avoid this by checking the controller in your filter:</p> <pre><code>if (filterContext.Controller is ErrorController) { return; } </code></pre> <p>This way, you won't redirect if you are already in your <code>ErrorController</code>.</p> <p>Another thing I would like to point out, is that using an <code>ActionFilter</code> in this way is probably not the most optimal solution. I think that you expect that your server will be online most of the time. This code however will run on each action. Instead of using an <code>ActionFilter</code> you can implement an <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iexceptionfilter%28v=vs.98%29.aspx" rel="nofollow">ExceptionFilter</a>. That filter will only run when something actually happened. Inside your exception filter you can check the reason for your exception and if you detect the server is down redirect to your <code>Error</code> controller.</p> <h2>UPDATE</h2> <p>After doing some research on how to exclude a global filter I found this blog post: <a href="http://haacked.com/archive/2011/04/25/conditional-filters.aspx" rel="nofollow">Conditional Filters in ASP.NET MVC 3</a>.</p> <p>Phil Haack describes how you can add a custom <code>IFilterProvider</code> that won't return your filter when you are on the <code>Error</code> controller. This is a very nice implementation where you control if the filter applies outside of the actual filter.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload