How OWIN Works When You Start ASP.NET

I looked through and searched for information on how things like OWIN hooks in ASP.NET actions.

I know if we create a standalone OWIN, we will call it manually, and it is clear that we are calling OWIN to get it working.

However, I see that OWIN is automatically called when ASP.NET starts without having to start a web start or something else. OWIN simply connects to ASP.NET and acts as an interceptor on every request.

My example would be signalr, we call the signal mapping in the OWIN module. However, I do not see anything that could call the OWIN configuration method. But signalr is already displayed and working.

How does OWIN intercept ASP.NET actions? Is it an OWIN that registers hooks or ASP.NET that now recognizes OWIN and calls automatically?

+5
source share
1 answer

Your project will have a similar line:

[assembly: OwinStartup(typeof(MyApp.Security.Authentication.Startup))] 

The line above tells the .NET class and method to be called at the beginning.

Alternative you can configure launch in WebConfig

 <appSettings> ... <add key="owin:appStartup" value="MyApp.Security.Authentication.Startup" /> ... </appSettings> 

From this point, you can place OWIN components, as well as any configuration items that you usually place in the Global.asax Application_Start event handler.

Delete the Global.asax class: If you use OWIN, you do not need to use the Gobal.asax class and fire the Application_Start event so that it can be deleted.

Sample Startup.cs Code

 using System.Web.Http; using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(MyApp.Security.Authentication.Startup))] namespace MyApp.Security.Authentication { public class Startup { public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); app.UseWebApi(config); } } } 

Edited by:

OWIN uses a launch class in which you can specify the components that you want to include in the application pipeline. If you look at the source code of Katana , the Katana SystemWeb host uses PreApplicationStartMethodAttribute to connect to the application. PreApplicationStartMethodAttribute, which is introduced in .NET 4, allows you to run code at an early stage in the ASP.NET pipeline when the application starts. I mean the way before, even to Application_Start.

Check out the "Owin Launch Class Detection" section in this link and the link about PreApplicationStartMethodAttribute.

+4
source

Source: https://habr.com/ru/post/1201503/


All Articles