zoukankan      html  css  js  c++  java
  • 在IIS集成管道中使用OWIN Middleware

    在Katana中启用Windows Authorization

    OWIN的架构:

    • Host 管理OWIN pipeline上运行的进程
    • Server 打开一个network socket,,监听请求
    • Middleware 处理HTTP请求并响应

    Katana当前提东两种server,都支持Windows Integrated Authentication

    • Microsoft.Owin.Host.SystemWeb 使用IIS的asp.net pipeline
    • Microsoft.Owin.Host.HttpListener 使用System.Net.HttpListener这是Katana的self-host方式的默认选择

    在IIS集成管道中使用OWIN Middleware

    在IIS集成管道中使用OWIN中间件,,通过将中间件注册到相应的pipeline event

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

    OWIN middleware Components (OMCs)

    IAppBuilder UseStageMarker()可以使用设置OMCs在指定的pipeline阶段执行

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

    app.UseStageMarker(PipelineStage.Authenticate)使所有此处前面注册的中间件,在authentication阶段执行

    OWIN Middleware component(OMC)可以一些阶段:

    public enum PipelineStage
    {
        Authenticate = 0,
        PostAuthenticate = 1,
        Authorize = 2,
        PostAuthorize = 3,
        ResolveCache = 4,
        PostResolveCache = 5,
        MapHandler = 6,
        PostMapHandler = 7,
        AcquireState = 8,
        PostAcquireState = 9,
        PreHandlerExecute = 10,
    }
    
    1. 默认,OMCs运行在PreHandlerExecute
    2. OWIN pipeline和IIS pipeline是有顺序的。现在设置的pipeline阶段不能早于之后设置的pipeline阶段。否则都将在后一个设置的阶段执行。
  • 相关阅读:
    Excel 相对引用与绝对引用
    SQL Update 巧用
    Delphi 多步操作产生错误,请检查每一步的状态值
    cxGrid 增加序号 (非数据库绑定模式) (测试通过)
    delphi cxgrid 使用方法
    如何使满足条件的数据显示不同的颜色
    Delphi中Format与FormatDateTime函数详解
    常用的日期时间函数
    100m和1000m网线的常见制作方法
    基于请求的分布式互斥算法
  • 原文地址:https://www.cnblogs.com/goodlucklzq/p/4500423.html
Copyright © 2011-2022 走看看