From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Support the ETag header

Support the ETag header - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Support the ETag header

- [Instructor] ASP.NET Core doesn't handle the ETag header out of the box. However, we can add ETag support with just a few lines of code. I've added some helper classes to the Infrastructure and Filters folder in the exercise files. You'll need to copy these files into your own project or simply open the solutions straight from the exercise files. Let's add an attribute that we can use to annotate methods similar to the response cache attribute. I'll add this to the Infrastructure folder and call this EtagAttribute. For AttributUsage we'll say that this needs to be used on a method and you can't use it more than once on the same method. This class needs to derive from Attribute and also from IFilterFactory. That's an internal ASP.NET Core filter interface. Let's implement that as a stub. We'll say IsReusable will return true here and then in CreateInstance, we'll do return new EtagHeaderFilter and we'll need to pull in the filters namespace. Let's go back over to the Info Route in…

Contents