2016-05-04 56 views
0

我有一個OWIN自主主機應用程序,爲提供單頁HTML應用程序提供簡單的開發Web服務器。由於我在外部編輯javascript,我想告訴服務器發回立即過期的緩存頭(以防止Chrome緩存)。.net Owin無主緩存的自主主機

我需要爲我的啓動添加什麼(請注意,此服務器啓用了文件瀏覽功能)。

class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      var hubConfiguration = new HubConfiguration(); 
      hubConfiguration.EnableDetailedErrors = (Tools.DebugLevel > 10); 
      hubConfiguration.EnableJavaScriptProxies = true; 
      app.UseCors(CorsOptions.AllowAll); 
      //app.UseStaticFiles(); 
      app.UseFileServer(new FileServerOptions() 
      { 
       //RequestPath = new PathString("/Scopes"), 
       EnableDirectoryBrowsing = true, 
       FileSystem = new PhysicalFileSystem(@".\Scopes"), 
      }); 
      app.MapSignalR("/signalr", hubConfiguration); 
     } 
    } 

回答

0

得到了在微軟的ASP論壇一些幫助:

https://forums.asp.net/p/2094446/6052100.aspx?p=True&t=635990766291814480

這是我做的,它的偉大工程:我添加了以下行啓動:

app.Use(typeof(MiddleWare)); 

...

class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     var hubConfiguration = new HubConfiguration(); 
     hubConfiguration.EnableDetailedErrors = (Tools.DebugLevel > 10); 
     hubConfiguration.EnableJavaScriptProxies = true; 
     app.UseCors(CorsOptions.AllowAll); 
     //app.UseStaticFiles(); 
     app.Use(typeof(MiddleWare)); 
     app.UseFileServer(new FileServerOptions() 
     { 
      //RequestPath = new PathString("/Scopes"), 
      EnableDirectoryBrowsing = true, 
      FileSystem = new PhysicalFileSystem(@".\Scopes"), 
     }); 
     app.MapSignalR("/signalr", hubConfiguration); 
    } 
} 

然後我定義了我的中間件:

using Microsoft.Owin; 
using System.Threading.Tasks; 

namespace Gateway 
{ 
    class MiddleWare : OwinMiddleware 
    { 
     public MiddleWare(OwinMiddleware next) 
     : base(next) 
     { 
     } 
     public override async Task Invoke(IOwinContext context) 
     { 
      context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate"; 
      context.Response.Headers["Pragma"] = "no-cache"; 
      context.Response.Headers["Expires"] = "0"; 
      await Next.Invoke(context); 
     } 
    } 
}