//指定类下的子类
Type helloType = typeof(ActionResult);
List<Type> types = new List<Type>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in assembly.GetTypes())
{
if (helloType.IsAssignableFrom(type))
{
if (type.IsClass && !type.IsAbstract)
{
types.Add(type);
}
}
}
}
for (int i=;i<types.Count;i++)
{
sb.AppendLine(types[i].Name);
}
var ret = sb.ToString();
      public FileStreamResult(Stream fileStream, string contentType);
public FileContentResult(byte[] fileContents, string contentType); var t = new ContentResult();
t.Content = "";
return t;
 报错 
public class AResult : ActionResult
{
// Properties
public string Content { get; set; }
public string ContentType { get; set; }
public int? StatusCode { get; set; } public override Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
return context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<AResult>>().ExecuteAsync(context, this);
}
//pivotPoint.get_X(); 改为 pivotPoint.x; }

        public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
}); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //注册
services.TryAddSingleton<IActionResultExecutor<AResult>>(); }

注册后报错

 public class AResult : ActionResult
{
// Properties
public string Content { get; set; }
public string ContentType { get; set; }
public int? StatusCode { get; set; }
public override Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
return context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<AResult>>().ExecuteAsync(context, this);
}
}
public class AResultExecutor : IActionResultExecutor<AResult>
{
private const string DefaultContentType = "text/plain; charset=utf-8";
private readonly IHttpResponseStreamWriterFactory _httpResponseStreamWriterFactory; public AResultExecutor(IHttpResponseStreamWriterFactory httpResponseStreamWriterFactory)
{
_httpResponseStreamWriterFactory = httpResponseStreamWriterFactory;
} public async Task ExecuteAsync(ActionContext context, AResult result)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
} if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
var response = context.HttpContext.Response;
ResponseContentTypeHelper.ResolveContentTypeAndEncoding(
null,
response.ContentType,
DefaultContentType,
out var resolvedContentType,
out var resolvedContentTypeEncoding); response.ContentType = resolvedContentType;
var defaultContentTypeEncoding = MediaType.GetEncoding(response.ContentType); if (result.Content != null)
{ string content = result.Content; response.ContentLength = resolvedContentTypeEncoding.GetByteCount(content);
using (var textWriter = _httpResponseStreamWriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
{
await textWriter.WriteAsync(content);
await textWriter.FlushAsync();
}
}
}
}
         services.TryAddSingleton<IActionResultExecutor<AResult>, AResultExecutor>();

详细

自定义ActionResult

https://blog.csdn.net/u014690615/article/details/85999853

net core 返回值的更多相关文章

  1. ASP.NET Core Mvc中空返回值的处理方式

    原文地址:https://www.strathweb.com/2018/10/convert-null-valued-results-to-404-in-asp-net-core-mvc/ 作者: F ...

  2. ASP.NET Core Web API处理HttpResponseMessage类型返回值的问题

    在将我们的 web api 从 .NET Framework 迁移至 .net core(asp.net core 1.1)之后,遇到一个问题. 之前返回值类型为 HttpResponseMessag ...

  3. Net Core 中间件实现修改Action的接收参数及返回值

    新一个WebApi项目(Net Core 2.1) 新建InputOutputAlterMiddleware类,修改命名空间为Microsoft.AspNetCore.Builder(不修改也没关系, ...

  4. Asp.net Core 异常日志与API返回值处理

    需求: 1.对异常进行捕获记录日志 并且修改返回值给前端 解释: ILogger4是自定义的一个日志,更改它就好 解决方案1: 使用中间件进行异常捕获并且修改其返回值 public class Err ...

  5. ASP.NET Core搭建多层网站架构【11-WebApi统一处理返回值、异常】

    2020/02/01, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[11-WebApi统一处理返回值.异常] 使用I ...

  6. ASP.NET Core中的Action的返回值类型

    在Asp.net Core之前所有的Action返回值都是ActionResult,Json(),File()等方法返回的都是ActionResult的子类.并且Core把MVC跟WebApi合并之后 ...

  7. net core webApi返回值

    1 多个参数采用结构的形式,如class xyz 2 返回值使用IActionResult 控制,不能使用httpRequestMessage类型 3 url为路由名称+Controller前缀 如下 ...

  8. asp.net core webapi 统一处理返回值、异常和请求参数验证

    现在的开发模式很少用asp.net mvc一个项目直接操作界面和数据库了.大部分都使用前后端分离,更多的是为了让API支持移动端. 后端写webapi的时候必然需要和前端约定请求值和返回值的格式,如果 ...

  9. Spring框架下的 “接口调用、MVC请求” 调用参数、返回值、耗时信息输出

    主要拦截前端或后天的请求,打印请求方法参数.返回值.耗时.异常的日志.方便开发调试,能很快定位到问题出现在哪个方法中. 前端请求拦截,mvc的拦截器 import java.util.Date; im ...

随机推荐

  1. python 并发编程 多线程与多进程的区别

    1.开进程的开销远大于开线程 2 同一进程内的线程共享该进程的数据,进程之间地址空间是隔离的 1 开进程的开销远大于开线程 from multiprocessing import Process de ...

  2. poj2407(欧拉函数模板题)

    题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p ...

  3. spring boot-9.对springMVC的支持

    1.thymeleaf spring boot 推荐的模板引擎是thymeleaf.spring boot 的自动配置已经默认配置好了themleaf,只要导入themleaf的Starter就可以了 ...

  4. mysql主要性能监控指标

    1.系统mysql的进程数 ps -ef | grep "mysql" | grep -v "grep" | wc –l 2.Slave_running mys ...

  5. Hbase 三维存储

    hbase所谓的三维有序存储的三维是指:rowkey(行主键),column key(columnFamily+qualifier),timestamp(时间戳)三部分组成的三维有序存储. 1.row ...

  6. 关于c++对拍的办法

    众所周知,在\(oi\)学习以及考试中,对拍是一件非常重要的事. 有了对拍后,我们可以利用它发现代码上的一些非常难看出来的错误. 编写对拍程序一般有两个办法. 方案一 编写一个对拍的\(cpp\),并 ...

  7. ping命令的七种用法

    能不能讲下ping命令的使用,其实对于命令的使用我们之前提到过一些,但对ping命令没有过多讲解,一般我们用的都是它的基本功能,今天我们来详细看下ping命令详细使用. 一.ping基本使用详解 在网 ...

  8. 十二、LaTex中数学公式多行排版

  9. :OpenCV人脸识别Fisherface算法源码分析

    https://blog.csdn.net/loveliuzz/article/details/73875904

  10. Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用

    在上一篇随笔里面 Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理,详细的讲解了Linux的动态磁盘管理LVM逻辑卷的基本概念以及LVM的工作原理, ...