zoukankan      html  css  js  c++  java
  • Owin 自定义中间件

    /// <summary>
        /// 自定义的中间件
        /// </summary>
        public class CustomMiddleware : OwinMiddleware
        {
            CustomMiddlewareParameters _parameter;
            public CustomMiddleware(OwinMiddleware next, CustomMiddlewareParameters parameter) : base(next)
            {
                _parameter = parameter;
            }
            public override Task Invoke(IOwinContext c)
            {
                if (Next != null)
                {
                    var msg = Encoding.UTF8.GetBytes(_parameter.ABC);
                    c.Response.ContentType = "text/html; charset=utf-8";
                    c.Response.WriteAsync(msg);
                    //处理操作
                    return Next.Invoke(c);
                }
                return Task.FromResult<int>(0);
            }
      public class CustomMiddlewareParameters {
    
            public string ABC { get; set; }
    
        }
        public static class CustomMiddlewareExtentions
        {
            public static IAppBuilder UseLYMMiddleware(this IAppBuilder builder)
            {
                return builder.Use<CustomMiddleware>(new CustomMiddlewareParameters { ABC="这是测试"});
    
            }
        
    
    }
    public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
              
                app.UseLYMMiddleware();
                app.Run(async context => await context.Response.WriteAsync("Hello World!"));
    
                // 有关如何配置应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=316888
            }
        }
  • 相关阅读:
    Git
    Git
    Git
    Git
    Docker
    Linux
    Linux
    Python
    Python
    SQL
  • 原文地址:https://www.cnblogs.com/liyouming/p/7840175.html
Copyright © 2011-2022 走看看