.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. nginx中使用srcache_nginx模块构建缓存

    nginx中可以将lua嵌,让nginx执行lua脚本,可以处理高并发,非阻塞的处理各种请求,openresty项目中可以使用nignx可以直接构建 srcache_nginx + redis 缓存, ...

  2. WCF使用net.tcp寄宿到IIS中(转)

    一.IIS部分 环境:Windows Server 2008 R2 1.安装WAS,如下图所示:   2.网站net.tcp协议绑定,如下图所示:   3.网站启用net.tcp,如下图所示:   二 ...

  3. MyEclipse下创建的项目导入到Eclipse中详细的图文配置方法

    一.情景再现. 有些人比较喜欢用Myeclipse开发,有些人却比较喜欢用eclipse开发.但是其中有一个问题,Myeclipse里面的项目导入的时候出现了一个小小的问题. 如下: 二.说明问题 导 ...

  4. Python Memcached Script

    介绍 利用 python 书写了 memcached 的启动等一类操作 尽量的实现脚本的复用性,以及脚本的可扩展性,已达到一劳永逸的效果, 并且添加了 memcached 监控搭建 memcached ...

  5. Merge Two Sorted Lists

    Merge Two Sorted Lists https://leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked ...

  6. UVALive 6073 Math Magic

                                                  6073 Math MagicYesterday, my teacher taught us about m ...

  7. html不使用cache数据

    <HEAD>      <META   HTTP-EQUIV="Pragma"   CONTENT="no-cache">     &l ...

  8. UVA 11235 Frequent Values ---RMQ

    大白书上的例题,具体讲解见大白书,最好用用一个Log数组直接求k,这样就是纯O(1)了 #include <iostream> #include <cstdio> #inclu ...

  9. JavaWeb学习之Servlet(三)----Servlet的映射匹配问题、线程安全问题

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140529.html 一.Servlet映射匹配问题: 在第一篇文章中的 ...

  10. 改造二叉树 (长乐一中模拟赛day2T1)

    1.改造二叉树 [题目描述] 小Y在学树论时看到了有关二叉树的介绍:在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随 ...