zoukankan      html  css  js  c++  java
  • .NET跨平台之OWEN中 过滤器的使用

    .NET中依赖IIS,通俗的说就是依赖IIS的程序集,导致我们的.NET项目就算是MONO到TOMCAT上,也无法使用,所以OWEN横空出世,OWEN定义了一套接口,接口定义了做.NET项目要实现的一些接口,OWEN本身通过这些接口获取到我们项目中的Request/Response,拿着这些去和Server(IISAPCHETOMCAT...)通信.

    回到正题,我们知道在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());
    }
    

      

  • 相关阅读:
    Jenkins简明入门(三) -- Blue Ocean,让一切变得简单
    TeamForge使用指南
    Jenkins简明入门(二) -- 利用Jenkins完成Python程序的build、test、deployment
    谈谈Python中的decorator装饰器,如何更优雅的重用代码
    Jenkins简明入门(一) -- 安装
    Python CSV 超简明用法
    Intel CPU命名规则的简略解析
    ef core 2.1 利用Query Type查询视图
    asp.net core 开发环境自定义域名及端口
    ef core 使用include进行外键连接查询
  • 原文地址:https://www.cnblogs.com/nopassword/p/5872835.html
Copyright © 2011-2022 走看看