zoukankan      html  css  js  c++  java
  • asp.net core 把上传的json转成string

        public class BodyReaderAttribute : ActionFilterAttribute
        {
            private string parameterName;
            public BodyReaderAttribute(string parameterName = "content")
            {
                this.parameterName = parameterName;
            }
    
            public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
            {
                var syncIOFeature = context.HttpContext.Features.Get<IHttpBodyControlFeature>();
                if (syncIOFeature != null)
                {
                    syncIOFeature.AllowSynchronousIO = true;
                }
    
                var request = context.HttpContext.Request;
                request.EnableBuffering();
                var reader = new StreamReader(request.Body);
                string content = reader.ReadToEnd();
                request.Body.Seek(0, SeekOrigin.Begin);
                context.ActionArguments.Add(this.parameterName, content);
    
                await base.OnActionExecutionAsync(context, next);
            }
        }
    
  • 相关阅读:
    用表组织数据
    SQL Server 2008创建数据库
    c#字符串常用方法
    属性升级介绍
    c#语法
    初识C#
    CSS动画
    YCSB性能测试工具使用
    高性能的Redis代理TwemProxy
    JVM垃圾回收总结
  • 原文地址:https://www.cnblogs.com/wh-blog/p/13559079.html
Copyright © 2011-2022 走看看