//指定类下的子类
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. C#后台正则表达式

    static Regex RegPhone = new Regex(@"^((1[34578][0-9]{1}))\d{8}");        static Regex RegN ...

  2. centos6/7如何通过命令挑选出IP地址

    ifconfig ens33 |sed -n '2p'|sed 's/^.*intet //;s@ netmask.*$@@  直接挑出IP地址 选择第二行打印, ifconfig ens33|sed ...

  3. spring boot-18.使用dubbo发布分布式服务

    我们新建两个项目分别模拟服务的提供者和服务的消费者,spring boot 集成dubbo主要分为以下几个步骤: 1.安装zookeeper 推荐使用docker 安装,使用以下几个命令即可完成 (1 ...

  4. Java初始和环境搭建

    前世今生 Java语言是什么? 一种计算机编程语言.名字取自咖啡. Java语言发展简史 Java语言之父:James Gosling SUN(Stanford University Network ...

  5. springboot - 应用实践(2)第一个springboot应用

    1.使用maven创建一个快速启动项目 2.引入相关依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...

  6. C++ day01 预备知识、C++综述、教材、推荐阅读。

    C++ day01: 1.预备知识? 1)什么是编程 编程,即编订程序. 程序 = 数据 + 算法(蛋糕 = 糖.鸡蛋.奶油 + 打鸡蛋.加糖.烤) 2)编程语言 最初的编程是用二进制代码(即“机器码 ...

  7. C++中的new/delete、构造/析构函数、dynamic_cast分析

    1,new 关键字和 malloc 函数区别(自己.功能.应用): 1,new 关键字是 C++ 的一部分: 1,如果是 C++ 编译器,则肯定可以用 new 申请堆空间内存: 2,malloc 是由 ...

  8. Linux如何查看进程是否启动,查看端口占用

    Linux系统中经常需要查看某个进程是否已经启动,启动位置在哪里,某个端口是否被占用,被哪个进程占用等,这些都可以通过命令来完成,本文讲述如何查看进程是否启动,查看端口占用 1.通过ps -ef | ...

  9. [.net core]7 4种app key value的配置方法及优先顺序

    就是这货 点开查看内容 { "Logging": { "LogLevel": { "Default": "Warning" ...

  10. java实现spark常用算子之coalesce

    import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...