Owin Middleware如何在IIS集成管道中执行
Owin Middleware Components(OMCs)
通过安装Install-Package Microsoft.Owin.Host.SystemWeb
可以让OMCs在IIS集成管道下工作
在IIS集成管道里,这个request pipeline 包含HttpModules关联到一组预定义的管道事件,例如
BeginRequest, AuthenticateRequest, AuthorizeRequest,等
如果我们将OMC和HttpModule进行比较,OMC也和HttpModule一样,必须要被注册到一个恰当的预定义的管道事件里,比如下面的这个Httpmodule,
当一个请求来到AuthenticateRequest阶段时,MyModule
会被调用
public class MyModule : IHttpModule
{
public void Dispose()
{
//clean-up code here.
}
public void Init(HttpApplication context)
{
// An example of how you can handle AuthenticateRequest events.
context.AuthenticateRequest += ctx_AuthRequest;
}
void ctx_AuthRequest(object sender, EventArgs e)
{
// Handle event.
}
}
为了使OMC取参与和HttpModule相同的基于事件的执行顺序,Katana运行时代码扫描Startup配置,并且把每个OMC关联到某个集成管道事件里,
比如下面的配置:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using System.Web;
using System.IO;
using Microsoft.Owin.Extensions;
[assembly: OwinStartup(typeof(owin2.Startup))]
namespace owin2
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "Middleware 1");
return next.Invoke();
});
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "2nd MW");
return next.Invoke();
});
app.Run(context =>
{
PrintCurrentIntegratedPipelineStage(context, "3rd MW");
return context.Response.WriteAsync("Hello world");
});
}
private void PrintCurrentIntegratedPipelineStage(IOwinContext context, string msg)
{
var currentIntegratedpipelineStage = HttpContext.Current.CurrentNotification;
context.Get<TextWriter>("host.TraceOutput").WriteLine(
"Current IIS event: " + currentIntegratedpipelineStage
+ " Msg: " + msg);
}
}
}
输出如下:
Current IIS event: PreExecuteRequestHandler Msg: Middleware 1
Current IIS event: PreExecuteRequestHandler Msg: 2nd MW
Current IIS event: PreExecuteRequestHandler Msg: 3rd MW
可以看到Katana运行时默认映射每个OMC到IIS管道事件PreRequestHandlerExecute
你可以根据需要调整这个OMC和管道事件的这种默认关系,具体使用一个扩展方法IAppBuilder UseStageMarker(),
像下面这样:
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "Middleware 1");
return next.Invoke();
});
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "2nd MW");
return next.Invoke();
});
app.UseStageMarker(PipelineStage.Authenticate);
app.Run(context =>
{
PrintCurrentIntegratedPipelineStage(context, "3rd MW");
return context.Response.WriteAsync("Hello world");
});
app.UseStageMarker(PipelineStage.ResolveCache);
}
输出如下:
Current IIS event: AuthenticateRequest Msg: Middleware 1
Current IIS event: AuthenticateRequest Msg: 2nd MW
Current IIS event: ResolveRequestCache Msg: 3rd MW
https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline
Owin Middleware如何在IIS集成管道中执行的更多相关文章
- 在IIS集成管道中使用OWIN Middleware
在Katana中启用Windows Authorization OWIN的架构: Host 管理OWIN pipeline上运行的进程 Server 打开一个network socket,,监听请求 ...
- python在管道中执行命令
简介 在实际开发中,可能在执行命令过程中,需要在命令的管道中输入相应命令后继续执行,因此需要在执行命令后在命令的管道中输入相应指令 方法一 直接使用communicate向管道传入所需指令,注意如果是 ...
- 如何在IIS 7.5中部署Asp.Net MVC 5的网站
0 Sign in to vote 系统是 windwos 2008 已经安装.Net 4.0 和 .Net 4.5 已经安装MVC4 的需要文件,MVC5 找不见下载地方,求各位大哥告知一下在哪里可 ...
- 如何在 ubuntu linux 一行中执行多条指令
cd /my_folder rm *.jar svn co path to repo mvn compile package install 使用&& 运算符连接指令 cd /my_f ...
- 中小研发团队架构实践之生产环境诊断工具WinDbg 三分钟学会.NET微服务之Polly 使用.Net Core+IView+Vue集成上传图片功能 Fiddler原理~知多少? ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一) C#程序中设置全局代理(Global Proxy) WCF 4.0 使用说明 如何在IIS上发布,并能正常访问
中小研发团队架构实践之生产环境诊断工具WinDbg 生产环境偶尔会出现一些异常问题,WinDbg或GDB是解决此类问题的利器.调试工具WinDbg如同医生的听诊器,是系统生病时做问题诊断的逆向分析工具 ...
- 为IIS Host ASP.NET Web Api添加Owin Middleware
将OWIN App部署在IIS上 要想将Owin App部署在IIS上,只添加Package:Microsoft.OWIN.Host.SystemWeb包即可.它提供了所有Owin配置,Middlew ...
- 在 IIS 7.5 中,应用程序池有两种运行模式:集成模式和经典模式。
应用程序池模式会影响服务器处理托管代码请求的方式. 如果托管应用程序在采用集成模式的应用程序池中运行,服务器将使用 IIS 和 ASP.NET 的集成请求处理管道来处理请求. 如果托管应用程序在采用经 ...
- 如何在 ASP.NET MVC 中集成 AngularJS(3)
今天来为大家介绍如何在 ASP.NET MVC 中集成 AngularJS 的最后一部分内容. 调试路由表 - HTML 缓存清除 就在我以为示例应用程序完成之后,我意识到,我必须提供两个版本的路由表 ...
- 如何在 ASP.NET MVC 中集成 AngularJS(2)
在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...
随机推荐
- Activiti工作流数据库表详细介绍
Activiti的后台是有数据库的支持,所有的表都以ACT_开头. 第二部分是表示表的用途的两个字母标识. 用途也和服务的API对应. ACT_RE_*: 'RE'表示repository. 这个前缀 ...
- git 的学习使用记录
git initls -ahgit add xxxgit commit -m "some message" git statusgit loggit log --pretty=on ...
- jQuery获取父级、兄弟节点的方法
一.jQuery的父节点查找方法 $(selector).parent(selector):获取父节点 $(selector).parentNode:以node[]的形式存放父节点,如果没有父节点,则 ...
- socket实现FTP上传下载功能
'''服务器端''' 1 _author__ = "Dbass" import socketserver import json,os class MyTCPHandler(soc ...
- 复习java基础
十进制转换成二进制: 方法:整除法,计数方式从右往左,二进制中非0即1.例子如下: 计数方式是从右往左进行,然后填写数字的顺序是余数优先 二进制转换成十进制: 方法:乘二法,例如二进制数字为: ...
- 使用MvvmCross框架实现Xamarin.Forms的汉堡菜单布局
注:本文是英文写的,偷懒自动翻译过来了,原文地址:Implementing MasterDetail layout in Xamarin.Forms by MvvmCross 欢迎大家关注我的公众号: ...
- 14.不同条目的listview
分类界面 整个项目的逻辑就是这样的 CategoryInfo public class CategoryInfo { private String title; private String url ...
- ubuntu下opencv的版本切换及遇到的问题解决
默认使用opencv 3.2的时候,使用SVM的时候,系统报错如下: error: ‘class MySVM’ has no member named ‘decision_func’ 解决方法:要把系 ...
- Liunx百宝箱(Centos补充)
Liunx可分为Redhat系列和debian系列,其采用的都是相同的Liunx内核,最大的不同点就是对RPM包的管理,使用的软件源不同.但相比之下debian系列的桌面端较好,Redhat其稳定性较 ...
- Python 游戏之旅(Pygame)
Pygame是跨平台Python模块,专为电子游戏设计,包含图像.声音.建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言和汇编语言)束缚.基于这样一个设想,所有需要的游戏功能和理念 ...