设为首页 收藏本站
查看: 752|回复: 0

[经验分享] Server in ASP.NET-Core

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-12-29 06:09:49 | 显示全部楼层 |阅读模式
.NET-Core Series

  • Server in ASP.NET-Core
  • DI in ASP.NET-Core
  • Routing in ASP.NET-Core
  • Error Handling in ASP.NET-Core
  • WebSocket in ASP.NET-Core(一)
  • WebSocket in ASP.NET-Core(二)
  • To be Continue...
Server in ASP.NET-Core
Before you read
   下面一些是来源.NET-Core官方文档中的一些内容,主要讲的是和Server 相关的一些内容,包括Kestrel 以及 ANCM . 对于理解.NET-Core 中的某些方面对我比较有帮助的,整理如下。基本是英文的,不难理解,就不翻译了。
ASP.NET Core Module
  What ASP.NET Core Module does
   ANCM is a native IIS module that hooks into the IIS pipeline and redirects traffic to the backend ASP.NET Core application.

   Requests come in from the Web and hit the kernel mode Http.Sys driver which routes them into IIS on the primary port (80) or SSL port (443). ANCM forwards the requests to the ASP.NET Core application on the HTTP port configured for the application, which is not port 80/443.
   Kestrel listens for traffic coming from ANCM. ANCM specifies the port via environment variable at startup, and the UseIISIntegration method configures the server to listen on http://localhost:{port}. There are additional checks to reject requests not from ANCM. (ANCM does not support HTTPS forwarding, so requests are forwarded over HTTP even if received by IIS over HTTPS.)
   Kestrel picks up requests from ANCM and pushes them into the ASP.NET Core middleware pipeline, which then handles them and passes them on as HttpContext instances to application logic. The application's responses are then passed back to IIS, which pushes them back out to the HTTP client that initiated the requests.
  ANCM port binding overrides other port bindings
   ANCM generates a dynamic port to assign to the back-end process. The UseIISIntegration method picks up this dynamic port and configures Kestrel to listen on http://locahost:{dynamicPort}/. This overrides other URL configurations, such as calls to UseUrls or Kestrel's Listen API Therefore, you don't need to call UseUrls or Kestrel's Listen API when you use ANCM. If you do call UseUrls or Listen, Kestrel listens on the port you specify when you run the app without IIS.
Kestrel
  When to use Kestrel with a reverse proxy


   A scenario that requires a reverse proxy is when you have multiple applications that share the same IP and port running on a single server. That doesn't work with Kestrel directly because Kestrel doesn't support sharing the same IP and port between multiple processes. When you configure Kestrel to listen on a port, it handles all traffic for that port regardless of host header. A reverse proxy that can share ports must then forward to Kestrel on a unique IP and port.
  PS: (About Host-Header) For example, the host header name for the URL http://www.cnblogs.com is www.cnblogs.com.
  UseUrls limitations
   You can configure endpoints by calling the UseUrls method or using the urls command-line argument or the ASPNETCORE_URLS environment variable. These methods are useful if you want your code to work with servers other than Kestrel. However, be aware of these limitations:

  • You can't use SSL with these methods.
  • If you use both the Listen method and UseUrls, the Listen endpoints override the UseUrlsendpoints.
  URL prefixes
   Only HTTP URL prefixes are valid; Kestrel does not support SSL when you configure URL bindings by using UseUrls.

  • IPv4 address with port number
  http://65.55.39.10:80/
  0.0.0.0 is a special case that binds to all IPv4 addresses.

  • IPv6 address with port number
  http://[0:0:0:0:0:ffff:4137:270a]:80/
[::] is the IPv6 equivalent of IPv4 0.0.0.0.


  • Host name with port number
  http://contoso.com:80/   http://*:80/
   Host names, *, and+, are not special. Anything that is not a recognized IP address or localhost will bind to all IPv4 and IPv6 IPs. If you need to bind different host names to different ASP.NET Core applications on the same port, use HttpSys or a reverse proxy server such as IIS, Nginx, or Apache.

  • Localhost name with port number or loopback IP with port number
  http://localhost:5000/   http://127.0.0.1:5000/   http://[::1]:5000/
   When localhost is specified, Kestrel tries to bind to both IPv4 and IPv6 loopback interfaces. If the requested port is in use by another service on either loopback interface, Kestrel fails to start. If either loopback interface is unavailable for any other reason (most commonly because IPv6 is not supported), Kestrel logs a warning.
Question Linked

  • https://q.cnblogs.com/q/97628/
  • https://q.cnblogs.com/q/97588/
Link Reference

  • https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x
  • https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x
  • PS: Kestrel is a cross-platform HTTP server based on libuv, a cross-platform asynchronous I/O library.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-429186-1-1.html 上篇帖子: swagger for c# webapi 下篇帖子: APP图标设计小技巧:在iOS上快速获得APP图标的真实预览图
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表