RickStrahl / Westwind.AspnetCore.LiveReload

ASP.NET Core Live Reload Middleware that monitors file changes in your project and automatically reloads the browser's active page
Other
469 stars 42 forks source link

UseLiveReload() breaks UseDeveloperExceptionPage() #39

Closed Andypro1 closed 3 years ago

Andypro1 commented 3 years ago

When using

if(env.IsDevelopment()) {
   app.UseDeveloperExceptionPage();
}

followed later by

app.UseLiveReload();

All pages which throw errors return a generic protocol error rather than the developer exception page.

Possible this may be related to the fact that the developer exception page can't be invoked if a response stream is started (according to the dotnet repo).

Edit: This is with the latest Westwind.AspnetCore.LiveReload version 0.2.10 and the latest .NET 5.0 preview (rc1, I think).

RickStrahl commented 3 years ago

Yes I can duplicate that, but I'm not sure if I can fix this. Ideally you have to put app.UseLiveReload() before any output generating component. Otherwise there will be problems because you may end up with half finished requests - as with the developer page.

The reason for this I think is this:

Because the pipeline runs FIFO, the inner request (LiveReload) gets aborted and all state associated is lost.

Guessing here based on behavior I see when debugging:

The original request is essentially aborted and a new one started. Now when the middleware gets to the end of hte request the original output stream hasn't been set yet if the middleware gets a hold of the request too late and so it basically took over the output stream but now that original stream is no longer there.

It works when UseLiveReload() is fired before any other requests, because the original stream is capture and apparently that's still available during the rewrite.

So you basically need to make sure UseLiveReload() is set before any output generating middleware.

Side effect:

In the process of debugging this I managed to figure out how to have the error page refresh now, so that's a bonus. So now when an error fires and the developer error page shows, and you then fix the code, the error page will refresh and show the fixed (or newly re-broken :smile:) page.

Andypro1 commented 3 years ago

Thanks Rick. UseLiveReload() does indeed work when placed first in Configure().