Wednesday, 30 August 2017

VB.Net webforms website requiring OWIN Middleware

I've recently been attempting to write a new API system from scratch using .Net Core in C# - just to progress my knowledge and skill set. At the moment, this bit isn't complete yet but I've been thinking ahead as to how current production systems would use it securely when I finally do complete it.

We have lots of VB.Net websites that we haven't had time to convert into anything else due to time constraints and they mainly use Forms Authentication.

At some point, I want to change the sites so that they use a different type of authentication - by linking to the API for an OAuth token. To get these sites to do this, I need to change them so that they use OWIN middleware which can then connect to the API. I won't go into more detail here as there are lots of explanations/examples around regarding this aspect.

The aspect I have struggled with is in terms of using OWIN middleware with the particular set-up we have.

Lots of searching around does return lots of examples. However, I must be looking for something that nobody else does because for the sample site I am going to use; it's VB (not C#); it's a web site (not a web application); it doesn't use ASP.Net Identity (it's a custom system); it doesn't use Entity Framework and it isn't MVC.

Take all those examples out of the Google Search results and, well without maybe going past the first 2 pages, there's nothing!

I created an example Visual Studio web application in VB.Net using individual user accounts for security and that worked which was the closest system. However, this is a web application, and so copying the important files from the sample to my site didn't actually work.

After lots of wasted hours, the solution is rather simple as I just had the location of the startup files wrong!

Instead of using App_Start and the root directory for the startup files as per the example applications - just put both files (Startup.vb and Startup.Auth.vb) in the App_Code folder.