2016-05-04 12 views
0

私は、単一ページのHTMLアプリケーションを提供するための簡単な開発Webサーバーを提供するために、OWIN自己ホストアプリケーションを用意しました。私はJavaScriptを外部から編集しているので、(キャッシュがキャッシュされないように)すぐに期限切れのキャッシュヘッダーを送り返すようにサーバーに指示する必要があります。.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); 
     } 
    } 
} 
関連する問題