This is part 2 of my series on “ASP.NET v5/Web API/vNext/OWIN, a beginner’s primer”.
Firstly, if you’re looking for a way to self host Web Forms from Katana, I am afraid that you are out of luck, it isn’t possible. What is possible is integrating OWIN Middleware and/or Web API into a Web Forms application, provided the application is running in an IIS integrated pipeline app pool.
Why would you use OWIN with Web Forms?
Maybe you just like Web Forms, and (despite some sneering on the web about using Web Forms at all) Microsoft have explicitly said that Web Forms will be developed for some time:
“You can continue developing Web Forms apps and have confidence that Web Forms is an essential part of the .NET web development platform. We remain focused on adding new features to Web Forms to improve the development experience and keep the technology up-to-date with web practices.” Microsoft
We had customers using ASP.NET 1.1 up until very recently, so let’s not forget that (notwithstanding security concerns) there is nothing wrong with an old app. on an older platform, if it gets the job done (note though you will need ASP.NET 4.5 to use OWIN middleware, or ASP.NET 4.0 for Web API).
Also, there are obviously a lot of legacy Web Forms applications out there that are being maintained and extended. I see no reason why you shouldn’t use OWIN Middleware, Web API (requires ASP.NET 4.0) or SignalR in those applications – and would argue that if you’re going to invest further in legacy apps (by adding new features) then at the very least you have an opportunity to work with newer technology and better still you may also ease the process of migration down the road (eg. converting an old app to MVC, and/or going natively mobile).
Web API, view composition on the client
The general trend in web development (specifically, SPA, Single Page Application architecture) is to have more numerous HTTP requests to smaller services. One view in your application might for example be composed of data from 5 services, services like notifications, shopping cart contents, a twitter feed, promotions and product listings. Older style design methodology would have had this view/page composed server-side in Web Forms, and sent to the browser. However SPA architecture and native mobile clients lead to composing the view on the client side.
Want to see an example? Press F12 in your browser, select Network tab and enable recording of traffic. Then visit Gmail.com and login. Even for an empty inbox, I got this much text based traffic (100+ requests in very little time).
This leads to the need for a leaner per request cycle on the server, because of course firing up the whole ASP.NET stack 5 times for one view is overkill. OWIN, and Web API resolve this problem for ASP.NET developers, by residing on Katana, the lean OWIN host.
Concrete/real-world example: stock quantity feature
Imagine that you have a retail oriented web application written in ASP.NET Web Forms. It runs on ASP.NET 4, and you’ve been tasked with adding a new feature to it; real time stock quantities. For the sake of the example, assume that for various technical reasons it is too slow to query stock levels from different warehouse locations every time a product page loads, and you must have an AJAX based ‘Check stock’ button. This article details how to use JQuery to obtain product information from Web API running under a Web Forms application.
OWIN Middleware Component (OMC) concrete example
I have to admit that when I started these posts I was excited that OMC might provide more opportunities for use than it has actually appeared to. Nearly all examples on the net for OMC relate to authentication (please see this article at CodeProject, or social login), security or logging. Certainly OMC has been used by SignalR and Web API, but the bottom line is that unless you are doing something very unique and innovative (at the same level as SignalR or Web API), it’s unlikely you’ll touch OMC much if at all. It is possible to do things with OMC instead of doing them through the existing (in Web Forms) and well trodden paths, such as; theming (you can redirect image and css requests to an appropriate brand for example), or general redirection, but I couldn’t think of an example of why you would do this unless your whole application is unconventional and requires an unconventional solution (which might be bad news in and of itself).
Here’s an article on getting started with OWIN and Katana if you would like to experiment with it.
A caveat about a lot of examples on the net using IAppBuilder, which is deprecated
OWIN probably has limited appeal to most ASP.NET developers, however it is the platform upon which better frameworks are built, such as Web API and SignalR. Overall, despite the possible confusions surrounding the .NET and ASP.NET ecosystem (i.e. just how complex they are in terms of numerous technological offerings) the future looks good for ASP.NET, and whether you choose Web Forms or MVC or HTML SPA, staying current with technology advances is as important as ever.
- Remote debug .NET applications over the internet with Visual Studio - November 14, 2016
- Craft and elegance in programming - May 19, 2016
- Bluetooth Low Energy in Windows 10: Troubleshooting Capabilities - August 31, 2015