.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. Cordova or Xamarin 用.net开发IOS和Android程序

    Visual Studio 2015 和 Apache Cordova 在开始前,问一下自己下面这些问题: 熟练掌握web技术的开发者比例是多少?(占所有开发者的比例) 熟练掌握移动开发技术(并且使用 ...

  2. Effective Java 45 Minimize the scope of local variables

    Principle The most powerful technique for minimizing the scope of a local variable is to declare it ...

  3. Remote Desktop Connection Manager (RDCMan) 介绍

    Remote Desktop Connection Manager介绍 Remote Desktop Connection Manager (RDCMan) 是微软Windows Live体验团队的主 ...

  4. centos7 新手基本命令

    1. yum update 安装系统后,更新yum到最新版本 提示错误 :cannot find a valid baseurl for repo: base/7/x86_64 解决:修改/etc/s ...

  5. Linux LDAP Server--->Clients配置

    Linux Ldap Configuration LDAP Server Base Software & SysTem Info SysTem Info 系统版本:centos 6.4 LDA ...

  6. poj 2391 Ombrophobic Bovines(最大流+floyd+二分)

    Ombrophobic Bovines Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 14519Accepted: 3170 De ...

  7. phpcmsv9 标题颜色显示问题

    在解决标题颜色问题之前首先要注意到 标题字段为title,副标题为fu_title. 如果一个文章想在首页推荐,又想在栏目首页推荐,并且这两个推荐位置的标题长度不一样,那只能用副标题区别,这样就可以在 ...

  8. UESTC 880 生日礼物 --单调队列优化DP

    定义dp[i][j]表示第i天手中有j股股票时,获得的最多钱数. 转移方程有: 1.当天不买也不卖: dp[i][j]=dp[i-1][j]; 2.当天买了j-k股: dp[i][j]=max(dp[ ...

  9. 抓取天猫和淘宝的详情页图片|Golang

    taobao.go package main import ( "crypto/md5" "encoding/hex" "fmt" &quo ...

  10. 字典树(Tire)模板

    #include<stdio.h> #include<string.h> #include<stdlib.h> struct node { node *ne[]; ...