Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a Visual Studio 2013 Project makes it a katana Project?

I just started my struggle to understand owin and katana. Following the Asp.Net tutorial I created a blank asp.net project in VS2013 and added a Nuget Package reference to Microsoft.Owin.Host.SystemWeb. The project I created is bear blank as shown.

enter image description here

This contains nothing except AssemblyInfo.cs, Web.config and packages.config. Now when I run(F5) this, it says

  • No assembly found containing an OwinStartupAttribute.
  • No assembly found containing a Startup or [AssemblyName].Startup class. To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config. To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

Now the question is how come just by adding a Nuget reference to Microsoft.Owin.Host.SystemWeb, it started to look for something specific to Owin like Startup class and so on as indicated in the error message? I mean I ran a different project without that Nuget reference and the error message is totally different. Nothing seems to have changed at least in the two files AssemblyInfo.cs, Web.config by adding the Nuget reference. As I understand adding the Nuget added a packages.config file and added some project reference. Also I have compared the project properties for the two projects tab by tab and I did not find any difference! So I wonder what in the world is causing the Owin project look for a Startup class?

like image 252
VivekDev Avatar asked Sep 23 '14 05:09

VivekDev


People also ask

What is Katana OWIN?

Katana is a flexible set of components for building and hosting Open Web Interface for . NET (OWIN)-based web apps. New development should use ASP.NET Core.

What is OwinStartup?

The OwinStartup attribute specifies the production startup class is run. Create another OWIN Startup class and name it TestStartup . Replace the generated code with the following: C# Copy.

What is Microsoft OWIN used for?

OWIN allows web apps to be decoupled from web servers. It defines a standard way for middleware to be used in a pipeline to handle requests and associated responses. ASP.NET Core applications and middleware can interoperate with OWIN-based applications, servers, and middleware.

What is OWIN IAppBuilder?

A middleware is a component that runs during request processing in an OWIN based application. These middleware components are generally added into the application by calling IAppBuilder. Use() method from the Startup class.


1 Answers

The secret is that Katana uses an ASP.NET feature called PreAppStart. You can see the source codes here:

https://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Host.SystemWeb/PreApplicationStart.cs

If an assembly in an ASP.NET app has this assembly-level attribute:

[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Initialize")]

Then ASP.NET will automatically run that code as the app starts. This code will run before "user" code will run, before even the Application_Start event. That's why it's called PreAppStart.

In the case of Katana, this code dynamically registers an ASP.NET HTTP Module (IHttpModule) that will eventually search for and attempt to call the app's startup/builder class. And if that fails, kablamo!

To disable the automatic behavior, add this line to web.config in the <appSettings> section:

<add key="owin:AutomaticAppStartup " value="false" />

More information on this behavior can be found on the www.asp.net site: http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection (same as the commenter mentioned).

like image 153
Eilon Avatar answered Oct 23 '22 00:10

Eilon