29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

using System.Web.Mvc;<br />

using Filters.Infrastructure;<br />

namespace Filters.Controllers {<br />

public class HomeController : Controller {<br />

[Authorize(Users = "admin")]<br />

public string Index() {<br />

return "This is the Index action on the Home controller";<br />

}<br />

[GoogleAuth]<br />

[Authorize(Users = "bob@google.com")]<br />

public string List() {<br />

return "This is the List action on the Home controller";<br />

}<br />

[HandleError(ExceptionType = typeof(ArgumentOutOfRangeException),<br />

View = "RangeError")]<br />

public string RangeTest(int id) {<br />

if (id > 100) {<br />

return String.Format("The id value is: {0}", id);<br />

} else {<br />

throw new ArgumentOutOfRangeException("id", id, "");<br />

}<br />

}<br />

}<br />

}<br />

[CustomAction]<br />

public string FilterTest() {<br />

return "This is the FilterTest action";<br />

}<br />

You can test the filter by starting the application and navigating to the /Home/FilterTest URL. The request from the<br />

browser will, of course, be a local connection and that will cause the custom action filter to generate a 404 error for the browser,<br />

as shown in Figure 18-7.<br />

486

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

Saved successfully!

Ooh no, something went wrong!