在 IIS 后面的 Azure WebApps 上部署 ASP.NET 5
Deploy ASP.NET 5 on Azure WebApps behind IIS
我在获取向托管在 Azure WebApps 上的 ASP.NET 5 应用程序发送请求的客户端的 IP 地址时遇到问题。
我的项目在完整的 CLR 运行 时间(不是 CoreCLR)上使用 ASP.NET 5 + MVC6 和 运行s。我在网上搜索了答案,但没有找到任何解决方案。
使用 的建议
我试过:
HttpContext.Connection.RemoteIpAddress
但是 HttpContext.Connection 中的属性都是 false 或 null,所以运气不好。
我注意到以下几点:当我通过 Visual Studio 使用 IIS Express 运行 我的应用程序时,来自 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...
}
Azure Web App 始终使用 IIS。
但是,对于 ASP.NET 5 代码,IIS 配置为使用 HttpPlatformHandler 将请求重定向到 ASP.NET 5 Web 服务器 Kestrel。
这是从 ASP.NET Beta 8 到 运行 ASP.NET 5 应用程序的方法。
您将通过打开 web.config 文件看到该配置。
参考资料:
- http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx
- https://github.com/aspnet/Announcements/issues/69
有一些与使用 Kestrel 时获取客户端 IP 地址相关的未解决问题,它们似乎在 RC2 版本中得到解决:
我在获取向托管在 Azure WebApps 上的 ASP.NET 5 应用程序发送请求的客户端的 IP 地址时遇到问题。
我的项目在完整的 CLR 运行 时间(不是 CoreCLR)上使用 ASP.NET 5 + MVC6 和 运行s。我在网上搜索了答案,但没有找到任何解决方案。
使用
HttpContext.Connection.RemoteIpAddress
但是 HttpContext.Connection 中的属性都是 false 或 null,所以运气不好。
我注意到以下几点:当我通过 Visual Studio 使用 IIS Express 运行 我的应用程序时,来自 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...
}
Azure Web App 始终使用 IIS。
但是,对于 ASP.NET 5 代码,IIS 配置为使用 HttpPlatformHandler 将请求重定向到 ASP.NET 5 Web 服务器 Kestrel。 这是从 ASP.NET Beta 8 到 运行 ASP.NET 5 应用程序的方法。 您将通过打开 web.config 文件看到该配置。
参考资料:
- http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx
- https://github.com/aspnet/Announcements/issues/69
有一些与使用 Kestrel 时获取客户端 IP 地址相关的未解决问题,它们似乎在 RC2 版本中得到解决: