Dies ist meine Startup.cs, wo ich meine Indexseite der Route '/ app' zuordne.Client-Caching bei Verwendung von statischen OWIN-Dateien konfigurieren
...
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
using Microsoft.Owin.Diagnostics;
[assembly: OwinStartup(typeof(conApi.Startup))]
namespace conApi
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
////Set static files
ConfigureFiles(app);
//Enable Cors
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
}
public void ConfigureFiles(IAppBuilder app)
{
app.Map("/app", spa =>
{
spa.Use((context, next) =>
{
context.Request.Path = new PathString("/index.html");
return next();
});
spa.UseStaticFiles();
});
}
}
}
Es wirkt wie ein Zauber, aber ich weiß nicht, wie das Client-Caching zu konfigurieren. Ich würde gerne wissen, wie man den Expires-Header setzt, wenn das möglich ist, wenn statische OWIN-Dateien verwendet werden?
SOLUTION
Tratcher vorgesehen, um die Verbindung zur StaticFilesOptions Klasse Dokumentation usw., die mich zu einer Lösung führen. Hinzugefügt wurde die StaticFilesOptions zum ConfigureFiles Methode wie folgt:
public void ConfigureFiles(IAppBuilder app)
{
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = (StaticFileResponseContext) =>
{
StaticFileResponseContext.OwinContext.Response.Headers.Add("Cache-Control",new[] { "public", "max-age=1000" });
}
};
app.Map("/app", spa =>
{
spa.Use((context, next) =>
{
context.Request.Path = new PathString("/index.html");
return next();
});
spa.UseStaticFiles(staticFileOptions);
});
}