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());
    }
    

      

  • 相关阅读:
    Ubuntu系统Anaconda安装Pytorch,教你如何优雅的安装环境(1-5)
    优雅的装系统------安装MacOS 10.13.5系统教程
    关闭Ubuntu系统更新方法
    毫秒钟搞定anaconda环境使用清华镜像安装OpenCV,教你如何优雅的安装环境(1-4)
    Ubuntu16.04安装Anaconda3并配置国内镜像,教你优雅的安装环境(1-3)
    Anaconda常用命令
    Ubuntu16.04安装CUDA10.2+cuDNN7.6.5(福利区),教你如何优雅的安装环境(1-2)
    Ubuntu16.04安装NVIDIA驱动,教你如何优雅的安装环境(1-1)
    简述 QPS、TPS、并发用户数、吞吐量关系
    Springboot验证注解@vaild的使用
  • 原文地址:https://www.cnblogs.com/nopassword/p/5872835.html
Copyright © 2011-2022 走看看