这是我对启动/托管web应用程序的理解,因为这一切都很令人困惑。一个小总结:
1. 典型的ASP。NET:只编写在强制IIS管道的最后一步中运行的应用程序代码
2. ASP。NET with OWIN:配置一个。NET web服务器并编写应用程序代码。不再直接耦合到IIS,因此您不再被迫使用它。
3.ASP。NET Core:配置主机和web服务器以使用和编写应用程序代码。如果你的目标是。net Core,而不是完整的。net框架,那么不再强制使用。net web服务器。
现在我将更详细地介绍它是如何工作的,以及使用哪些类来启动应用程序:
典型的ASP。网
Classic ASP.NET applications have the Global.asax file as entry point. These applications can only be run in IIS and your code gets executed at the end of the IIS pipeline (so IIS is responsible for CORS, authentication... before your code even runs). Since IIS 7 you can run your application in integrated mode which integrates the ASP.NET runtime into IIS. This enables your code to configure functionality which wasn't possible before (or only in IIS itself) such as url rewriting in the Application_Start event of your Global.asax file or use the new <system.webserver> section in your web.config file.
ASP。NET with OWIN
First of all OWIN is not a library but a specification of how .NET web servers (for example IIS) interact with web applications. Microsoft themselves have an implementation of OWIN called project Katana (distributed through several different NuGet packages). This implementation provides the IAppBuilder interface you encounter in a Startup class and some OWIN middleware components (OMC's) provided by Microsoft. Using IAppBuilder you basically compose middleware in a plug-and-play way to create the pipeline for the webserver (in addition to only the ASP.NET pipeline in IIS7+ as in the point above) instead of being tied to the IIS pipeline (but now you use a middleware component for CORS, a middleware component for authentication...). Because of this, your application is not specifically coupled to IIS anymore and you can run it on any .NET Webserver, for example:
OwinHost包可以用一个Katana web服务器自托管你的应用程序。
systemweb包用于以集成模式在IIS7+中托管您的OWIN应用程序,方法是在内部将您的中间件订阅到正确的生命周期事件。
让人困惑的是环球公司。asax仍然与OWIN Startup类一起被支持,尽管它们都可以做类似的事情。例如,您可以在全局中实现CORS。asax和使用OWIN中间件的身份验证,这变得非常混乱。
我的经验法则是移除全局。asax文件,以便在需要添加OWIN时使用启动。
ASP。网络核心
ASP。NET Core是下一个进化,现在你可以瞄准。NET Core或者完整的。NET框架。当你瞄准。net Core时,你可以在任何支持。net标准的主机上运行你的应用程序。这意味着你不再局限于一个。net web服务器(如前一点),而是可以在Docker容器中托管你的应用程序,linux web服务器,IIS…
ASP的入口点。NET Core web应用程序是Program.cs文件。在这里,您配置了主机,并再次指定了配置管道的Startup类。使用OWIN(通过使用IAppBuilder。UseOwin扩展方法)是可选的,但完全支持。