標籤:
.NET中依賴IIS,通俗的說就是依賴IIS的程式集,導致我們的.NET項目就算是MONO到TOMCAT上,也無法使用,所以OWEN橫空出世,OWEN定義了一套介面,介面定義了做.NET項目要實現的一些介面,OWEN本身通過這些介面擷取到我們項目中的Request/Response,拿著這些去和Server(IIS\APCHE\TOMCAT...)通訊.
回到正題,我們知道在MVC中,可以有
public override void OnActionExecuted(ActionExecutedContext filterContext)
public override void OnAuthorization(AuthorizationContext filterContext)
...
OWEN中就是
namespace Owin{ /// <summary> /// An ordered list of known Asp.Net integrated pipeline stages. More details on the ASP.NET integrated pipeline can be found at http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx /// </summary> public enum PipelineStage { /// <summary> /// Corresponds to the AuthenticateRequest stage of the ASP.NET integrated pipeline. /// </summary> Authenticate, /// <summary> /// Corresponds to the PostAuthenticateRequest stage of the ASP.NET integrated pipeline. /// </summary> PostAuthenticate, /// <summary> /// Corresponds to the AuthorizeRequest stage of the ASP.NET integrated pipeline. /// </summary> Authorize, /// <summary> /// Corresponds to the PostAuthorizeRequest stage of the ASP.NET integrated pipeline. /// </summary> PostAuthorize, /// <summary> /// Corresponds to the ResolveRequestCache stage of the ASP.NET integrated pipeline. /// </summary> ResolveCache, /// <summary> /// Corresponds to the PostResolveRequestCache stage of the ASP.NET integrated pipeline. /// </summary> PostResolveCache, /// <summary> /// Corresponds to the MapRequestHandler stage of the ASP.NET integrated pipeline. /// </summary> MapHandler, /// <summary> /// Corresponds to the PostMapRequestHandler stage of the ASP.NET integrated pipeline. /// </summary> PostMapHandler, /// <summary> /// Corresponds to the AcquireRequestState stage of the ASP.NET integrated pipeline. /// </summary> AcquireState, /// <summary> /// Corresponds to the PostAcquireRequestState stage of the ASP.NET integrated pipeline. /// </summary> PostAcquireState, /// <summary> /// Corresponds to the PreRequestHandlerExecute stage of the ASP.NET integrated pipeline. /// </summary> PreHandlerExecute, }}
差不多夠用了。
代碼會這麼寫:
首先要確定攔截到這個過濾器之後,要幹啥
app.Use(typeof(OAuthBearerAuthenticationMiddleware), app, options);
OAuthBearerAuthenticationMiddleware是時間了OWEN介面的自訂中介軟體,授權用
然後定義中介軟體在哪個過濾器注入
object obj;if (app.Properties.TryGetValue("integratedpipeline.StageMarker", out obj)){var addMarker = (Action<IAppBuilder, string>)obj;addMarker(app, PipelineStage.Authenticate.ToString());}
.NET跨平台之OWEN中 過濾器的使用