29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

you run the application and navigate to /Customer URL, you will see the result shown in Figure 18-13.<br />

Figure 18-13. Multiple filters on the same action method<br />

The MVC Framework executes the B filter before the A filter, but it could have been the other way around. The MVC<br />

Framework does not guarantee any particular order or execution. Most of the time, the order does not matter. When it does, you<br />

can use the Order property, as shown in Listing 18-49.<br />

Listing 18-49. Using the Order Property in a Filter<br />

using System.Web.Mvc;<br />

using Filters.Infrastructure;<br />

namespace Filters.Controllers {<br />

public class CustomerController : Controller {<br />

}<br />

}<br />

[SimpleMessage(Message = "A", Order = 1)]<br />

[SimpleMessage(Message = "B", Order = 2)]<br />

public string Index() {<br />

return "This is the Customer controller";<br />

}<br />

The Order parameter takes an int value, and the MVC Framework executes the filters in ascending order. In the listing, I<br />

have given the A filter the lowest value, so the framework executes it first, as shown in Figure 18-14.<br />

497

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!