【问题标题】:Deploy ASP.NET 5 on Azure WebApps behind IIS在 IIS 后面的 Azure WebApps 上部署 ASP.NET 5
【发布时间】:2015-12-30 11:25:16
【问题描述】:

我在获取向 Azure WebApps 上托管的 ASP.NET 5 应用程序发送请求的客户端的 IP 地址时遇到问题。

我的项目使用 ASP.NET 5 + MVC6 并在完整的 CLR 运行时(不是 CoreCLR)上运行。我已经在网上搜索了答案,但没有找到任何解决方案。

使用来自Get the client's IP address 的建议 我试过了:

HttpContext.Connection.RemoteIpAddress

但是来自 HttpContext.Connection 的属性都是 false 或 null,所以这里没有运气。

我注意到以下情况:当我通过带有 IIS Express 的 Visual Studio 运行我的应用程序时,Connection.RemoteIpAddress 的 IP 可用。 当我通过命令行运行 dnx web 时,属性为空。似乎 azure 在 dnx 上运行我的应用程序,而不是 IIS。

所以我的问题是: 如何配置项目并将其部署到 Azure WebApps,使其在 IIS 之后运行,因此 HttpContext.Connection 将填充其值?

我目前的配置(project.json的摘录):

(...)
    "compilationOptions": {
        "emitEntryPoint": true
      },
    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel",
        "ef": "EntityFramework.Commands"
      },

      "frameworks": {
        "dnx451": { }
      },
(...)

以及 Startup.cs 的 Configure 方法

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{  
    app.UseIISPlatformHandler();
    //rest of the method...

}

【问题讨论】:

  • 我已经回答了问题的第一部分(IIS/Kestrel)。关于客户端IP,包Microsoft.AspNet.IISPlatformHandler和中间件UseIISPlatformHandler()应该按照github.com/aspnet/Templates/issues/189转发客户端IP。你确定要用吗?
  • 这会重定向我本地实例上的 IP,但不会重定向到已部署的 Azure 网站。

标签: asp.net-core azure-web-app-service asp.net-core-mvc dnx kestrel-http-server


【解决方案1】:

Azure Web App 始终使用 IIS。

但是,对于 ASP.NET 5 代码,IIS 配置为使用 HttpPlatformHandler 将请求重定向到 ASP.NET 5 Web 服务器 Kestrel。 这是从 ASP.NET Beta 8 运行 ASP.NET 5 应用程序的方式。 您将通过打开 web.config 文件看到该配置。

参考资料:

在使用 Kestrel 时,有一些与获取客户端 IP 地址相关的未解决问题,这些问题似乎在 RC2 版本中得到了解决:

【讨论】:

猜你喜欢
  • 2022-01-13
  • 2017-08-30
  • 1970-01-01
  • 2016-03-04
  • 2023-02-06
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
相关资源
最近更新 更多