我刚刚将我的Azure Web App从aspnetcore rc2更新为aspnetcore 1.0,.net framework 4.6.2和预览2工具。由于这个改变,我遇到了一个问题,在部署后的第一分钟左右,我的控制器没有获得任何POST数据。应包含它的对象始终为null。大约一分钟后,代码开始按预期工作。 第一次网络通话的响应时间现在看起来要快得多,让我怀疑在应用程序完全初始化之前我的应用程序正在发送请求。只有在部署到Azure时,才会在本地发生这种情况。
在开始接收请求之前,我是否需要做些什么来确保应用程序完全初始化?
如果我尝试直接访问this.HttpContext.Request.Body,那么它会抛出
Cannot access a disposed object. Object name: 'FileBufferingReadStream'.
我的project.json看起来像是相关的:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"runtimeOptions": {
"gcServer": true
},
"dependencies": {
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.AspNetCore.Hosting": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Newtonsoft.Json": "9.0.1"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net462": {
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"userSecretsId": "redacted",
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
控制器的代码非常简单。在第一分钟左右,这将返回badrequest,之后相同的请求将返回Ok。
[HttpPost]
[Produces( "application/json" )]
public IActionResult Post( [FromBody] MyRequestDataClass RequestData )
{
if (RequestData == null)
{
return BadRequest();
}
return Ok();
}