ASP.NET Core Run Middleware behave differently with different browser.

Amit Singh Rawat 731 Reputation points
2021-07-24T13:16:08.137+00:00

Below is my middleware code:

app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
ctx.Context.Response.Headers[HeaderNames.CacheControl] =
"public,max-age=10"; // Here I placed my first breakpoint
}
});
app.Run(async context =>
{
await context.Response.WriteAsync("<html><body><a href='images/image1.jpg' target='_blank'>Click for Image1</a></body></html>"); // Here is my Second Breakpoint
});

I placed a break point within Run Middleware as well as with in UseStaticFiles Middleware.
I just cached the static files for 10 seconds.
Then I click on Anchor tag created with in my run middle ware from browser. When I hit this anchor tag from chrome. First time it hit both the break point and rightly so. From next time onward, it only hit Second break point. If it is cached then it should not hit our application. And cache is working that's why UseStaticFiles is not hit.

But when I hit via Firefox. From second request onward it never hit our Run Middleware. Even after cache duration is over. After 10 second it hit UseStaticFiles but not RUN middleware.

What is happening. Any idea?

Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Fei Xue - MSFT 1,111 Reputation points
    2021-07-29T01:57:32.877+00:00

    Please check the cache-control headers for the static files to see whether this http header is added to the response expected and cache settings in the browser to see if the cache is disabled. If the browser doesn't follow the http cache headers, it is recommend that submit the issue for that specific browsers.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.