From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

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

Cookies using message handlers

Cookies using message handlers

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Cookies using message handlers

- [Instructor] On the last part, we learned how to use cookies within Web API controllers. Another option is to use a message handler because a message handler is invoked before a controller in the pipeline. So let's go to Visual Studio and see this in action. Here, go to the Solution Explorer, then right-click on the Custom Handlers and add a new class. I'm going to rename this class the Session ID Handler and, for this class to be a message handler, we need to inherit from the base class Delegating Handlers. So Delegating Handlers. Let us import the necessary namespace which is the System.Net.Http. And next, let us override the Send Async method, so Override Send Async method. The first thing that we need to do is that we need to define a session ID token value, so for that, let's write: Public Static String. We define this as a static because we want to be able to access it from another class without having to create…

Contents