2
當我使用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);
「測試」從未寫入響應。我試圖使用另一箇中間件,它等到StaticFiles中間件執行:
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);
但是,這沒有奏效。我如何修改回覆?