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.
source share