2014-04-17 161 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); 
      } 
     } 
    }); 
} 
相关问题