how can I modify the response before it is sent to the client when I use Microsoft.Owin.StaticFiles?
FileServerOptions options = new FileServerOptions();
options.FileSystem = new Microsoft.Owin.FileSystems.PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, "Content/"));
options.DefaultFilesOptions.DefaultFileNames = new string[] { "index.htm", "index.html" };
options.StaticFileOptions.OnPrepareResponse = (r) =>
{
r.OwinContext.Response.WriteAsync("test");
};
options.EnableDefaultFiles = true;
app.UseFileServer(options);
"test" is never written into the response. I tried to use another middleware which waits until the StaticFiles Middleware is executed:
app.Use((ctx, next) =>
{
return next().ContinueWith(task =>
{
return ctx.Response.WriteAsync("Hello World!");
});
});
FileServerOptions options = new FileServerOptions();
options.FileSystem = new Microsoft.Owin.FileSystems.PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, "Content/"));
options.DefaultFilesOptions.DefaultFileNames = new string[] { "index.htm", "index.html" };
options.EnableDefaultFiles = true;
app.UseFileServer(options);
But this didn't work. How can I modify the response?