I wrote a middleware for resize image in asp.net core. but this middleware only works if browser has been not cached. first call middleware is ok but from second call, the request does not enter middleware. after clear cache in browser(ctrl+f5) the request enters middleware. How is this problem solved?
stratup.cs
namespace ImageResizer
{
public class Startup
{
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
Configuration = builder.Build();
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.Configure<SiteSettings>(Configuration.GetSection(nameof(SiteSettings)));
services.AddImageResizer();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseImageResizer();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
//app.UseStaticFiles();
var pathImage = Configuration.GetSection("SiteSettings").Get<SiteSettings>().ImageLocation;
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(pathImage)),
RequestPath = "/StaticFiles"
});
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}