This is my Startup.cs, where I link my index page to the '/ app' route.
... 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) {
It works like a charm, but I don’t know how to configure client caching. I would like to know how to set the Expires header if this is possible when using static OWIN files?
DECISION
Tratcher provided a link to the documentation of the StaticFilesOptions classes, etc., which led me to the solution. Added StaticFilesOptions method to ConfigureFiles method, for example:
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); }); }
caching owin
Marcus höglund
source share