Zero Content-Length for static file on Ubuntu #2082
Description
I've developed SPA application (ASP core,MVC,Angular) on Windows but can not host it on Linux. When I reload webpage in browser by F5 Kestrel prints out error and webbrowser receives HTTP code 500. This happens every second reload.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HL81HU49MSPA", Request id "0HL81HU49MSPA:00000002": An unhandled exception was thrown by the application.
System.InvalidOperationException: Response Content-Length mismatch: too few bytes written (0 of 42).
Environment:
#dotnet --info
.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/2.0.0/Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
Steps to reproduce:
- Create new MVC application:
#dotnet new mvc
- Place file named 1.txt with any content into wwwroot
- Change Home/Index controller method to:
public IActionResult Index()
{
return File("~/1.txt", "text/plain");
}
#dotnet run
Now, If you try to open localhost:5000 browser will show content of the 1.txt, if you press F5 it'll show error 500. Press F5 again and it'll display content of 1.txt again, etc...
I tried to change Startup.cs to (as stated in #1289 ):
app.UseStaticFiles(new StaticFileOptions(){
OnPrepareResponse=context=>{
context.Context.Response.Headers.Remove("Content-Length");
}
});
, but this does not help.
If I set breakpoint in Home/Index controller method it is hit every time (i.e. on every reload). But it returns content-length=0 on every even reload. On every odd reload it returns correct value.