You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
If some middleware replaces context.Response.Body with new stream and does not return original one back (due to exception, for example) - then all subsequent requests (to other middleware!) in this keep-alive connection (that's important) will return empty body.
Sample Startup.cs:
usingSystem;usingMicrosoft.AspNetCore.Builder;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.AspNetCore.Http;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Logging;namespaceIISIntegrationResponseBug{publicclassStartup{publicstaticvoidMain(string[]args){varhost=newWebHostBuilder().UseKestrel().UseContentRoot(System.IO.Directory.GetCurrentDirectory()).UseStartup<Startup>().Build();host.Run();}publicvoidConfigureServices(IServiceCollectionservices){// Nothing}publicvoidConfigure(IApplicationBuilderapp,ILoggerFactoryloggerFactory){loggerFactory.AddConsole(LogLevel.Debug);app.UseDeveloperExceptionPage();app.Use(async(context,next)=>{if(context.Request.Path=="/fail"){varoriginalResponse=context.Response.Body;context.Response.Body=newSystem.IO.MemoryStream();// ^^^^ This is a causethrownewException();}if(context.Request.Path=="/"){awaitcontext.Response.WriteAsync("Hello, World");return;}awaitnext.Invoke();});}}}
Now start app, open browser and navigate to http://localhost:5000/ - "Hello World" is shown, good.
Now open http://localhost:5000/fail - nothing is shown. A little strange (where is DeveloperExceptionPage?), but the most interesting is ahead...
Open http://localhost:5000/ again - nothing is shown. There is no "Hello World" here.
Middleware had been called and produced an answer, but it's lost. You will never receive any response body in this keep-alive connection.
The text was updated successfully, but these errors were encountered:
If some middleware replaces
context.Response.Body
with new stream and does not return original one back (due to exception, for example) - then all subsequent requests (to other middleware!) in this keep-alive connection (that's important) will return empty body.Sample
Startup.cs
:Sample
project.json
(nothing special, just FYI):Now start app, open browser and navigate to
http://localhost:5000/
- "Hello World" is shown, good.Now open
http://localhost:5000/fail
- nothing is shown. A little strange (where is DeveloperExceptionPage?), but the most interesting is ahead...Open
http://localhost:5000/
again - nothing is shown. There is no "Hello World" here.Middleware had been called and produced an answer, but it's lost. You will never receive any response body in this keep-alive connection.
The text was updated successfully, but these errors were encountered: