Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All depends what exactly you want to do, and how. Three options below:</p> <hr> <p>You can use route constraints for this. They are executed when evaluating the route to match to.</p> <pre><code>routes.MapRoute( "HomeWithConstraint", "Home/{action}", new {controller="Home", action="index"}, new { x = new MyCustomRouteConstraint () } ); // without constraint, i.e. if above didnt pass routes.MapRoute( "HomeWithConstraint", "Home/{action}", new {controller="Home", action="index"} ); </code></pre> <p>The MyCustomRouteConstraint type above would check for x==0 etc in your example. Not sure exactly what you want to do, but this will allow you to check conditions before running and set additional route values etc.</p> <p>See <a href="http://www.asp.net/learn/mvc/tutorial-25-cs.aspx" rel="noreferrer">here</a> for example of custom route constraints.</p> <hr> <p>Alternativly, yes you can use a custom ActionFilter, just apply it to the controller class, and it will be called before any action is executed. Something like:</p> <pre><code>public class CheckXActionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if(x == 0) { // do something // e.g. Set ActionParameters etc } else { // do something else } } } </code></pre> <hr> <p>Another option is to have all you controllers (or the relevant ones) inherit from a custom controller you make, and override :</p> <pre><code>OnActionExecuting </code></pre> <p>See <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller_methods(v=VS.100).aspx" rel="noreferrer">here</a> for details.</p> <p>To do the same as the filter, or routing constraints.</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.
    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