.NET跨平台之OWEN中 過濾器的使用

來源:互聯網
上載者:User

標籤:

.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中 過濾器的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.