.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中 过滤器的使用的更多相关文章

  1. AspNet MVC3中过滤器 + 实例

    AspNet MVC3中过滤器 + 实例 过滤器在请求管线注入额外的逻辑,提供简单优雅的方法实现横切点关注(AOP),例如日志,授权,缓存等应用.通过AOP可以减少在实际的业务逻辑中参杂过多非直接业务 ...

  2. flask中过滤器的使用

    过滤器 过滤器的本质就是函数.有时候我们不仅仅只是需要输出变量的值,我们还需要修改变量的显示,甚至格式化.运算等等,而在模板中是不能直接调用 Python 中的某些方法,那么这就用到了过滤器. 使用方 ...

  3. JSP中过滤器的设置

    JSP中过滤器的设置 package com.filter; import java.io.IOException; import java.net.URLDecoder; import java.u ...

  4. SpringBoot图文教程6—SpringBoot中过滤器的使用

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文系列教程技术大纲 鹿老师的Java笔记 SpringBo ...

  5. Struts2中过滤器和拦截器的区别

    拦截器和过滤器的区别: 1.拦截器是基于java的反射机制的,而过滤器是基于函数回调 2.过滤器依赖与servlet容器,而拦截器不依赖与servlet容器 3.拦截器只能对action请求起作用,而 ...

  6. Java Web 中 过滤器与拦截器的区别

    过滤器,是在java web中,你传入的request,response提前过滤掉一些信息,或者提前设置一些参数,然后再传入servlet或者struts的 action进行业务逻辑,比如过滤掉非法u ...

  7. SpringBoot中过滤器、监听器以及拦截器

    属于javax.servlet所提供的Api 拦截器原理 简单来讲是通过动态代理实现,被访问的目标方法通过代理类(方法)来执行,这样我们就可以在真正要执行的方法执行前.后做一些处理: 通过拦截器这种方 ...

  8. 【过滤器】web中过滤器的使用与乱码问题解决

    一.过滤器Filter 1.filter的简介 filter是对客户端访问资源的过滤,符合条件放行,不符合条件不放行,并且可以对目   标资源访问前后进行逻辑处理 2.快速入门 步骤: 1)编写一个过 ...

  9. JAVAWEB开发中过滤器的概述及使用

    1.什么是过滤器? 过滤器是向WEB应用程序的请求和响应添加功能的WEB服务组件 2.过滤器的作用 1)可以统一的集中处理请求和响应 2)可以实现对请求数据的过滤 3.过滤器的工作方式 4.使用场合 ...

随机推荐

  1. INFORMATICA 的部署实施 MTP&MTS

    软件开发的一般都有三个环境,开发环境,用户接受度测试环境,生产环境.我最近实施了从开发环境到生产环境的部署工作,在此跟大家分享一下. 大概步骤如下: 1 备份生产环境INFORMATICA 知识库  ...

  2. HTTP 协议的头部

    转自:http://network.51cto.com/art/201509/490594.htm HTTP首部字段有四种类型:通用首部字段,请求首部字段,响应首部字段,实体首部字段. 通用首部字段: ...

  3. linux基本命令学习笔记

    这个几天在研究linux的常用基本命令.以下是此时间内的幻灯片截图笔记,在这里留个脚印. linux 常用命令 1,命令的基本格式 2,文件处理命令 3,文件搜索命令 4,帮助命令 5,压缩解压缩命令 ...

  4. JavaScript中奇葩的假值

    通常在以下语句结构中需要判断真假 if分支语句 while循环语句 for里的第二个语句 如 if (boo) { // do something } while (boo) { // do some ...

  5. KEIL与ADS1.2共存

    出现的问题: 原来电脑已经安装了ADS1.2.现在安装keil5编译一个32位新唐单片机程序时,出现了如下错误: Error: L6411E: No compatible library exists ...

  6. POJ 2777 Count Color(线段树之成段更新)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...

  7. Hadoop blocks

    一In cases where the last record in a block is incomplete, the input split includes location informat ...

  8. PL/0 词法分析器

    PL/0 词法分析器 #include<stdio.h> #include <ctype.h> #include <stdlib.h> #include <s ...

  9. bzoj-3444 3444: 最后的晚餐(组合数学)

    题目链接: 3444: 最后的晚餐 Time Limit: 5 Sec  Memory Limit: 128 MB Description [问题背景] 高三的学长们就要离开学校,各奔东西了.某班n人 ...

  10. HDU 2065 “红色病毒”问题 --指数型母函数

    这种有限制的类棋盘着色问题一般可以用指数型母函数来解决,设Hn表示这样的着色数,首先H0=1,则Hn等于四个字母的(A,B,C,D)的多重集合的n排列数,其中每个字母的重数是无穷,且要求A,C出现的次 ...