ASP.NET Web API 2托管差异 [英] ASP.NET Web API 2 hosting differences

查看:64
本文介绍了ASP.NET Web API 2托管差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现Web API 2可以通过2种技术托管:

I have found out that Web API 2 can be hosted with 2 techniques:

  • A)IIS-Web应用程序
  • B)OWIN-控制台应用程序

但是我找不到它们之间的区别.我为什么要在另一个上使用?有什么优点或缺点吗?

But what I couldn't find is the difference between them. Why should I use one over the other? Are there any advantages or disadvantages?

推荐答案

请注意,IIS和OWIN并非互斥的.您可以在IIS中托管OWIN应用程序:

Note that IIS and OWIN are not mutually exclusive. You can host an OWIN application in IIS: https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana#host-owin-in-iis

因此,从这里开始,假设您要询问IIS托管应用程序与自托管OWIN应用程序之间的区别(因为您提到了控制台应用程序).

So from here let's assume you are asking about the distinction between IIS hosted apps versus self hosted OWIN apps(since you mentioned console app).

IIS

  • IIS具有更全面的功能和更成熟的功能.IIS已经内置了许多功能.
  • IIS具有广泛的集成,例如管理界面.
  • IIS由经验丰富的开发人员和管理员所熟知,因此利用IIS意味着您可以确定所使用的IIS功能已被有经验的人员记录在案并得到了理解.
  • IIS可以轻松地在域的单个端口(例如端口80)后面托管多个站点.托管多个Web应用程序时,它们都可以在端口80上访问,并且IIS可以根据域或域将请求路由到适当的应用程序网址.
  • IIS is more full featured and mature. There's a wide range of features already built into IIS.
  • IIS has a wide range of integrations such as management interfaces.
  • IIS is well known by experienced devs and administrators, and thus leveraging IIS means that you can be sure IIS features you use are documented and understood by experienced staff.
  • IIS can easily host multiple sites behind a single port on a domain, such as port 80. When you host multiple web apps, they are all accessible on port 80, and IIS can route requests to the appropriate app based on domain or URL.

OWIN

  • 默认情况下,OWIN自托管不能在单个端口上托管多个站点.每个进程都分配有一个端口.通常,自托管的Web应用程序是其自己的进程(例如控制台应用程序),因此已为其分配了端口.您可以利用IIS或另一个Web主机应用程序通过端口80将代理请求反向到您的许多自托管应用程序,并根据诸如URL之类的路由.或者,您也可以编写自己的端口路由器.
  • 如上所述,您不能在与IIS相同的服务器上拥有自托管应用程序,并且它们都响应端口80.一个端口需要位于其他端口.再次,IIS可以拥有80个反向代理,并且可以反向代理自托管OWIN应用所在的端口.
  • OWIN使您可以更好地控制请求/响应管道.在ASP.NET中,通过请求处理程序和模块可以完成很多工作,但是存在某些局限性或行为限制,在某些情况下这些行为很难克服.OWIN打开处理管道,以提供更多控制权.
  • 您需要完成一些事情,可以轻松找到处理程序和模块,但是可能还没有合适的OWIN中间件实现.许多常见任务随时可用,并且维护良好的开放源代码库已经支持OWIN.因此,这主要适用于不太常见的边缘情况.
  • 自我托管使您无需在计算机上使用IIS.只要遵循某些准则,就可以将正确构建的OWIN应用程序部署到Linux并通过Linux Web主机(例如Apache)来反向代理请求.OWIN应用程序可以由Kestrel自行托管.

显然不是完整列表.

我认为,今后最好在IIS中使用OWIN.这是因为OWIN正在迅速成为标准.我认为对于大多数了解它的人来说,如果选择的话,他们会每次都选择OWIN进行新项目,因为这与旧项目没有冲突.而且由于IIS是一个非常成熟,安全,功能齐全且稳定的Web托管应用程序,因此我们选择在IIS中托管OWIN Web应用程序.这也意味着该Web应用将经过测试,并与基于IIS的云服务(例如Azure App Service)兼容.

I think going forward it's probably advisable to use OWIN in IIS. This is because OWIN is quickly becoming the standard. I think for most people who understand it, if given the choice they would choose OWIN everytime for new projects, given there is no conflict with legacy projects. And since IIS is a very mature, secure, full featured, and stable web hosting application, then we choose to host our OWIN web app in IIS. This also means the web app will be tested and compatible with IIS based cloud services such as Azure App Service.

这篇关于ASP.NET Web API 2托管差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆