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 ...
随机推荐
- 【LeetCode】188、买卖股票的最佳时机 IV
Best Time to Buy and Sell Stock IV 题目等级:Hard 题目描述: Say you have an array for which the ith element i ...
- windows VS2013中使用<pthread.h>
1. 下载pthreads-w32-2-9-1-realease.zip 地址:http://www.mirrorservice.org/sites/sourceware.org/pub/pthrea ...
- etcd集群添加节点
查看当前集群节点信息 # etcdctl member list --write-out=table +------------------+---------+------------------- ...
- Java初始和环境搭建
前世今生 Java语言是什么? 一种计算机编程语言.名字取自咖啡. Java语言发展简史 Java语言之父:James Gosling SUN(Stanford University Network ...
- Kibana server is not ready yet出现的原因
第一点:KB.ES版本不一致(网上大部分都是这么说的) 解决方法:把KB和ES版本调整为统一版本 第二点:kibana.yml中配置有问题(通过查看日志,发现了Error: No Living con ...
- luogu P4631 [APIO2018] Circle selection 选圆圈
传送门 那个当前半径最大的圆可以用堆维护.这道题一个想法就是优化找和当前圆有交的圆的过程.考虑对于所有圆心建KD-tree,然后在树上遍历的找这样的点.只要某个点子树内的点构成的矩形区域到当前圆心的最 ...
- iOS App沙盒目录结构
转自:http://blog.csdn.net/wzzvictory/article/details/18269713 出于安全考虑,iOS系统的沙盒机制规定每个应用都只能访问当前沙盒目录下面的文件( ...
- Scala Nothing 从官方DOC翻译
Nothing is - together with scala.Null - at the bottom of Scala's type hierarchy. Scala中的Nothing和Null ...
- 爬虫获取网页数据,报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start by
https://blog.csdn.net/hj_xy_0705/article/details/85011072
- nova计算服务分布式
控制节点 #第一步 控制节点下载nova-conpute包 #安装依赖包 #vim /etc/nova/nova.conf [DEFAULT] my_ip=#当前节点IP use_neutron = ...