daveharney (15) [Avatar] Offline
#1
Filters definitely present some challenging concepts and it took me quite awhile to get through this chapter. But, once again, I learned a lot. Also, I found the sample projects are essential in trying to understand how filters work. The diagrams can provide a conceptual understanding but I found that I really needed to follow the code also.

The first problem I had in trying to follow the code in the “FilterPipelineExample” project, was seeing the console output. I contacted the author who explained that VS2017 defaults to using IIS Express and this needs to be changed to the project name.

The second sample project builds on the “RecipeApplication” project from Chapter 12. I modified my version of that project to add the “EnsureRecipeExists” filter but with a small change to create a custom error report straight from the filter. This was another challenge for me and once again I contacted the author for guidance. As it turns out, the solution is very simple using a slight variation on the sample code:

Original sample code for the filter:
context.Result = new NotFoundResult();


Change for custom report:
context.Result = new RedirectToActionResult("MyErrorPage", "MyError", new { myID = recipeId });