net core 返回值

//指定类下的子类
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 返回值的更多相关文章
- ASP.NET Core Mvc中空返回值的处理方式
原文地址:https://www.strathweb.com/2018/10/convert-null-valued-results-to-404-in-asp-net-core-mvc/ 作者: F ...
- ASP.NET Core Web API处理HttpResponseMessage类型返回值的问题
在将我们的 web api 从 .NET Framework 迁移至 .net core(asp.net core 1.1)之后,遇到一个问题. 之前返回值类型为 HttpResponseMessag ...
- Net Core 中间件实现修改Action的接收参数及返回值
新一个WebApi项目(Net Core 2.1) 新建InputOutputAlterMiddleware类,修改命名空间为Microsoft.AspNetCore.Builder(不修改也没关系, ...
- Asp.net Core 异常日志与API返回值处理
需求: 1.对异常进行捕获记录日志 并且修改返回值给前端 解释: ILogger4是自定义的一个日志,更改它就好 解决方案1: 使用中间件进行异常捕获并且修改其返回值 public class Err ...
- ASP.NET Core搭建多层网站架构【11-WebApi统一处理返回值、异常】
2020/02/01, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[11-WebApi统一处理返回值.异常] 使用I ...
- ASP.NET Core中的Action的返回值类型
在Asp.net Core之前所有的Action返回值都是ActionResult,Json(),File()等方法返回的都是ActionResult的子类.并且Core把MVC跟WebApi合并之后 ...
- net core webApi返回值
1 多个参数采用结构的形式,如class xyz 2 返回值使用IActionResult 控制,不能使用httpRequestMessage类型 3 url为路由名称+Controller前缀 如下 ...
- asp.net core webapi 统一处理返回值、异常和请求参数验证
现在的开发模式很少用asp.net mvc一个项目直接操作界面和数据库了.大部分都使用前后端分离,更多的是为了让API支持移动端. 后端写webapi的时候必然需要和前端约定请求值和返回值的格式,如果 ...
- Spring框架下的 “接口调用、MVC请求” 调用参数、返回值、耗时信息输出
主要拦截前端或后天的请求,打印请求方法参数.返回值.耗时.异常的日志.方便开发调试,能很快定位到问题出现在哪个方法中. 前端请求拦截,mvc的拦截器 import java.util.Date; im ...
随机推荐
- python基础语法之集合set
1 概念 集合是一个无需的,不重复的数组组合,它的主要作用如下: 去重,将一个列表装换成集合,会将其去重 关系测试,测试两组数据的交集,差集,并集等关系. 集合对象是一组无需排列的可哈希的值,集合成员 ...
- 【转】应用宝基于Robotium自动化测试
(转载:http://tmq.qq.com/2016/05/robotium_for_app_test/) 1 背景目的应用宝项目组采用FT(Feature Team)模式,整个项目组分为多个FT,而 ...
- deepin之添加右键新建文档选项
deepin之添加右键新建文档选项 虽然Linux系统下所有皆文件,创建各种文件很简单,也很随意,但还是有人讨厌采用先创建空文件再改文件名的方式(比如我),我还是喜欢右键新建一个相应的源文件,可是默认 ...
- Sqoop-MySQL导入hive时id为文本解决
错误如下 // :: ERROR tool.ImportTool: Import failed: java.io.IOException: Generating splits for a textua ...
- [转帖]LSB
LSB 简介 冯 锐2006 年 8 月 07 日发布 https://www.ibm.com/developerworks/cn/linux/l-lsb-intr/ 学习一下 之前 不知道LSB_R ...
- jsp运行环境的安装和配置
1.JDK的安装和配置 1)下载jdk,我下载的是1-jdk-6u26-windows-i586.exe,放在D:\StudySystem\JavaWeb\jdk目录下. 2)安装jdk,直接你下载的 ...
- python爬取天气后报网
前言 大二下学期的大数据技术导论课上由于需要获取数据进行分析,我决定学习python爬虫来获取数据.由于对于数据需求量相对较大,我最终选择爬取 天气后报网,该网站可以查询到全国各地多年的数据,而且相对 ...
- php 数组助手类
ArrayHelper.php <?php /** * php 数组助手类 * Class ArrayHelper * @package app\helper */ class ArrayHel ...
- JS拖拽系列--多元素拖拽,面向对象,es6拖拽
最近不太忙,终于有时间,研究了一下早就想搞定的拖拽系列,先是写了面向过程式的,再做一个面向对象的,再顺便弄弄继承,最后玩一下ES6的class 不觉用了一天多,收获很大.拖拽弄完,想再弄一个拖放. ...
- 浏览器给openresty连接发送参数请求,查询数据库,并返回json数据
nginx.conf配置文件 #user nobody; worker_processes 1; error_log logs/error.log; #error_log logs/error.log ...