2014-04-17 157 views

回答

0

該屬性指定的類被OWIN框架用來啓動應用程序。請參閱本教程中的示例:http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection

+1

謝謝,但它仍然是不明確的「應用程序」是否指的是全球應用程序在所有瀏覽器的服務器級別,'或',應用爲每個HTTP請求看到它。 –

+0

它指向您的應用程序,它將由服務器啓動,並將服務多個Http請求。啓動類被調用來啓動應用程序,而不是每個Http請求。 –

0

OwinStartupAttribute裝飾的類每AppDomain執行一次。


另一方面,OWIN中間件由微軟的OWIN實現管理,並將在每個請求中執行一次。

例如Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware如下所示。在這些封面之下,CookieAuthenticationHandler類被OWIN多次提交給服務器,例如圖像,腳本,頁面等等。您可以在OnValidateIdentity中放置一個斷點以查看此行爲並查看Context.Request.Path

簡而言之,雖然您的「啓動」類根據AppDomain被調用一次,但您的回調代表像OnValidateIdentity將根據http請求觸發一次。

public void ConfigureAuth(IAppBuilder app) 
{ 
    // app.UseCookieAuthentication(...) is only called once per AppDomain 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
     LoginPath = new PathString("/Account/Login"), 
     Provider = new CookieAuthenticationProvider 
     { 
      // callback delegate is called once per http request 
      OnValidateIdentity = ctx => 
      { 
       return ctx.RejectIdentity(); // Reject every identity. No one can log into my app! It's that secure. 
       return Task.FromResult<object>(null); 
      } 
     } 
    }); 
} 
相關問題