Intro to OWIN talk and a simple IP filtering middleware sample

Last week I introduced OWIN during a brown bag talk at Southworks. I’m by no means an expert on the subject, but the reason I decided to do it was that I felt it was very hard for me to find a single blog post/video that provided the information required to understand what OWIN was, why it exists and how it can be used.

That’s why while preparing the talk I decided to create a Github repository to store the source, slides, demo script and some links in a single, centralized place. Please, head over to the site if you would like to check out the slides or get more context on OWIN, as I won’t be including everything in this post.

image

I also realized that this provides an easy way to share the asset’s once the talk is over, so I’ll probably continue doing this in the future.

IP Filtering Middleware

As you learned from checking the Github project out, OWIN allows you to setup a pipeline of middleware components that are allowed to inspects, routes, or modifies request and/or response messages. With the goal of providing a simple sample, I used Katana (Microsoft’s implementation of OWIN) to create an IP filtering middleware component. It allows you to provide a simple Func to determine whether a request should be rejected based on the client’s IP address. Of course this is not something that you would use in production, but it gives an idea of the kind of things that can be achieved with OWIN and Katana.

I also created an extension method that allows you to easily integrate the middleware component into the pipeline:

Integrating with the pipeline

For example, if you wanted to reject requests that are not from a private network nor the local machine you could set things up like this:

Wrapping up

This is by no means a full intro to OWIN (for that refer to the resources provided in Github), but I hope it provides an initial idea of the kind of things that you can do with OWIN and Katana.

If you have feedback please let me know.