What is the new Startup.cs file for Visual Studio 2013 projects?

I just installed Visual Studio 2013, created an MVC Web Application project, and noticed a new file in the project template called Startup.cs.

What is it, how is it different from Global.asax.cs, and are there any good recommendations for using this?

+49
visual-studio-2013 asp.net-mvc owin
Nov 17 '13 at 17:53
source share
3 answers

Each OWIN application has a launch class in which you specify the components for the application pipeline.

If you run a new Visual Studio project, you will see OWIN fragments. OWIN is a specification that defines an API for a framework and servers for collaboration. The OWIN point is to shut down the server and application. For example, ASP.NET Identity uses OWIN security, its own hosting SignalR uses OWIN hosting, etc. All examples use OWIN, so all of them must have a launch class defined in the file "Startup.cs".

The Global.asax application file, an ASP.NET application, is an optional file that contains code for responding to application-level events raised by ASP.NET or HttpModules.

More details:

Owin

http://www.asp.net/aspnet/overview/owin-and-katana

Global.asax

http://msdn.microsoft.com/en-us/library/1xaas8a2(v=vs.71).aspx

You can find more ideas about why OWIN in the following article:

http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana

+31
Nov 19 '13 at 2:54 on
source share

The file seems to be associated with SignalR. Quoting VS 2013 Release Notes :

Built on OWIN

SignalR 2.0 is fully integrated into OWIN (open web interface for. NETWORK). This change makes the configuration process for SignalR much more compatible between web hosting and self-service SignalR applications, but also required a number of API changes.

MapHubs and MapConnection are now MapSignalR

For compatibility with OWIN standards, these methods have been renamed to MapSignalR. MapSignalR, called without parameters, displays all the hubs (as MapHubs does in version 1.x); To display individual PersistentConnection Objects, specify the connection type as the type parameter and the URL extension for the connection as the first argument.

The MapSignalR method is called in the Owin launch class. visual Studio 2013 contains a new template for the Owin launch class; To use this template, do the following:

  • Right click project
  • Select Add, New Item ...
  • Select the Owin launch class. Name the new class Startup.cs.

In a web application, the Owin launch class containing the MapSignalR method is added to the Owin launch process by writing to the application settings of the node in the Web.Config file, as shown below.

In a self-service application, the Startup class is passed as the type parameter of the WebApp.Start method.

+6
Nov 17 '13 at 18:04 on
source share

The launch class is the convention that Katana / OWIN looks for to initialize the pipeline. When your application starts, the code inside the Configuration function starts to configure the components that will be used. In MVC 5 templates, it was used to bind authentication middleware, which is all built on top of OWIN.

If you want to use dependency injection with OWIN, check out this project on GitHub: DotNetDoodle.Owin.Dependencies

+5
Dec 04 '13 at 17:08
source share



All Articles