asp.net-core-webapi 相关问题

有关不依赖于MVC视图或Razor页面的ASP.NET核心Web API和Web应用程序的问题

ASP.NET Core 6 Web API 中的流式响应在本地工作,但不在 Windows 上托管的 Azure Web 应用程序上工作

我将服务作为 Azure Web 应用程序运行。问题是响应流没有被接收,因为它们是由应用程序发送的,而是大块的。我的假设是这是由于响应缓冲造成的。我的AS...

回答 1 投票 0

API 不会返回与对象实际保存的数据相同的数据

我正在使用 C# 开发一个 API,用户可以在其中估算该特定计算实例的云成本。 我正在返回 Dictionary 类型的字典 我正在使用 C# 开发一个 API,用户可以在其中估算该特定计算实例的云成本。 我返回一个类型为 Dictionary<string, Dictionary<string, CloudProduct>> 的字典,其中第一个字符串是“aws”,第二个字符串是“onDemand”、“1Y”、“3Y”和“Storage”。 它看起来像这样: { "aws": { "OnDemand": { "cpu": 2, "ram": 4 }, "1Y": { "cpu": 2, "ram": 4 }, "3Y": { "cpu": 2, "ram": 4 }, "storage": { "capacity": "200" } } } 在这本词典中,有类 ComputeOffer 和 Storage。这两个类都继承自类CloudProduct。 这是返回数据的代码: [HttpPost] public JsonResult getRequest(CloudCalculationRequest ccr){ if(ccr.RequestedProviders.Contains("aws")){ foreach(CloudProduct cloudProduct in ccr.CloudProducts){ AWSCaldulator.AddCosts(cloudProduct, ccr.PurchaseOption); } } JsonResult result = new JsonResult(ccr); return result; } 使用调试器,我可以看到直到它返回的最后一刻result,数据都是正确的并且类被正确识别: 然而,用户收到的一切都是: "providers": { "aws": { "OnDemand": { "description": "", "name": "", "location": "string" }, "1Y": { "description": "", "name": "", "location": "string" }, "3Y": { "description": "", "name": "", "location": "string" }, "storage": { "description": "", "name": "", "location": "" } } 这些是 CloudProduct 和 Storage 继承自的 ComputeOffer 类的唯一参数。 我认为这是因为框架需要一个 CloudProduct 实例,然后使用默认值而不是实际数据。 你没有分享什么是CloudCalculationRequest, CloudProduct, ComputeOffer, Storage and AWSCaldulator.AddCosts,所以我只能根据我的假设写一个示例。恐怕您对数据类型感到困惑。这是我的代码和测试结果。 [HttpPost("PcCost")] public JsonResult getRequest(CloudCalculationRequest ccr) { var dict = new Dictionary<string, CloudProduct> { { "OnDemand", new ComputeOffer{ cpu = "2", ram = "4"} }, { "1Y", new ComputeOffer{ cpu = "2", ram = "4"} }, { "3Y", new ComputeOffer{ cpu = "2", ram = "4"} }, { "storage", new Storage{ capacity = "200"} } }; var aws = new Dictionary<string, Dictionary<string, CloudProduct>> { { "aws", dict} }; ccr.aws = aws; ccr.aws2 = dict; JsonResult result = new JsonResult(ccr); return result; } public class CloudCalculationRequest { public string RequestedProviders { get; set; } public List<CloudProduct> CloudProducts { get; set; } public Dictionary<string, Dictionary<string, CloudProduct>> aws { get; set; } public Dictionary<string, CloudProduct> aws2 { get; set; } } public class CloudProduct { public string description { get; set; } public string name { get; set; } public string location { get; set; } } public class ComputeOffer : CloudProduct { public string cpu { get; set; } public string ram { get; set; } } public class Storage : CloudProduct { public string capacity { get; set; } } 然后我用输入参数进行测试,例如 { "RequestedProviders":"aws", "CloudProducts":[ { "description": "desc1", "name": "name1", "location": "loca1" }, { "description": "desc2", "name": "name2", "location": "loca2" } ], "aws":{}, "aws2":{} } 我的 API 响应如下图所示。 就像你看到的,如果我们在 public Dictionary<string, Dictionary<string, CloudProduct>> aws { get; set; } 中定义 CloudCalculationRequest,那么我们就会从 providers 中得到 aws。如果我们定义 new Dictionary<string, CloudProduct> 但在字典中使用 new ComputeOffer and new Storage,则 CloudProduct 中的属性也会被返回。

回答 1 投票 0

ASP.NET 承载身份验证,不适用于 swagger。正在与邮递员合作

我正在尝试为我的 ASP.NET Web api 设置身份验证。我已使用 Firebase Google 作为我的身份提供商添加了 jwt 身份验证。 当我尝试通过 swagger ui 进行身份验证时,我可以

回答 0 投票 0

beanstalk 上的 ASP.NET Core Web API - 如何更改 URL Swagger

我有一个 ASP.NET Core 6 Web API,并且我在 AWS 上创建了一个 Beanstalk 环境来启动该 API。我可以使用 https://localhost:7182/swagger/index.html 在本地加载 API。 但我想不通...

回答 1 投票 0

无法使用具有一对多关系的 C# 类中的 Swagger 创建记录

我正在尝试使用 ASP.NET Core API 和 Angular 创建预订类型网站。 我陷入了模型/关系的困境。 这是酒店模型类: 公级酒店 { [钥匙] 公共国际酒店...

回答 1 投票 0

创建可路由访问现有数据库的 .NET Core Web APOI [已关闭]

目前我正在阅读一些有关使用数据库优先方法创建 Web API 的文档。我注意到大多数教程都会将其表迁移到应用程序上。我如何制作一个网络...

回答 2 投票 0

访问 web.config 中现有的连接字符串到新的 .NET Core Web API

我是 .NET Core Web API 的新手。我能够使用这里提供的文档和帮助创建 .NET Core Web API。文档显示了一种通过放置

回答 1 投票 0

ASP.NET Core Web API:基本身份验证+证书映射

我有一个使用基本身份验证的 ASP.NET Core Web API,并且需要 SSL。 我有 services.AddAuthentication(o => { o.DefaultScheme = IISDefaults.Authentication...

回答 1 投票 0

无法翻译 LINQ 表达式。方法翻译失败

我想返回 ItemNos(字符串)列表,即使很少有字符匹配,即使字符在不同位置匹配。 例如:如果我传入“appl”或“apole”或“daple&q...

回答 2 投票 0

使用方法代码在 ASP.NET Core Web API 中创建文件夹 wwroot

我正在为我的 Web 应用程序的背面开发 ASP.NET Core Web API,前面是 Angular。我需要在我的服务器中保存图像或 PDF 等内容并访问它们,所以我想将这些文件保存在...

回答 1 投票 0

如何针对我的场景在 ASP.NET Core 6 Web API 中设置默认版本控制?

刚刚意识到我对 ASP.NET Core 6 Web API 版本控制的理解是错误的。 这是我的控制器: [API版本(“1.0”)] [API控制器] [授权] 公共类 FundController {...

回答 3 投票 0

.net core web api 中的响应压缩

我们正在尝试使用.net core web api中的以下包来实现响应压缩,以获得更好的性能。 Microsoft.AspNetCore.ResponseCompression - 版本 2.2.0 然而,我们已经意识到...

回答 1 投票 0

ASP.NET Core Web API 接收包含 IFormFile 的请求正文,但来自 Angular 的所有属性均为 null

我正在尝试发送一个请求主体,它是一个从 Angular 到 ASP.NET Core Web API 的对象。除 ID 外,所有属性均显示为空。 网络应用程序接口: 公开课图书 { 公共 int BookID { 获取; ...

回答 1 投票 0

如何在ASP.NET Core 8 Web API项目中使用C#读取图像文件并将其返回到前端客户端以在浏览器中显示

从 ASP.NET Core 8 Web API 项目中,我尝试将图像作为文件流返回到前端客户端以在浏览器中显示。 我写了下面的代码 使用 (var 流 = 文件。

回答 1 投票 0

我想在 Asp .net core Web API POST 方法中传递很长的字符串作为参数?

我想在 Asp .net core Web API POST 方法中传递很长的字符串作为参数,但是当我传递它时,它只需要开始几个单词。如何解决这个问题? 我传递的数据: { &q...

回答 2 投票 0

如何显示在 Visual Studio 上创建的 ASP.NET Core Web API 项目上缺少的节点?

我安装了 Visual Studio Community 2022,其中包含 ASP.NET 和 Web 开发工作负载以及 .NET 8.0 运行时 (LTS)。 当我在上述模板和 ASP.NET Core 上创建项目时...

回答 1 投票 0

Angular 到 ASP.NET Core Web API 为所有属性、对象传递返回 NULL(一个属性是 IFormFile)

我正在尝试将 Angular 对象发送到 ASP.NET Core Web API。除 ID 外,所有属性均显示为空。 网络应用程序接口: 公开课图书 { 公共 int BookID { 获取;放; } 公共字符串? ISB...

回答 1 投票 0

.NET 8 Azure 数据库用户管理身份

我有一个使用 Entity Framework Core 的 ASP.NET Core 8 Web API。我在 Azure Linux 服务应用程序上部署我的应用程序。 我的 API 连接到 Azure SQL Server 数据库。我使用用户管理的IDE...

回答 1 投票 0

无法反序列化从 Webapi 返回的 ProblemDetails

我有两个用 C# 编写的微服务,在 .NET 8.0 上运行。 WebApiOne 有一个实现 IExceptionHandler 的 GlobalHandler,它返回以下内容: var 问题详细信息 = 新问题详细信息 ...

回答 1 投票 0

ASP.NET Core Web API:重定向到 Angular

似乎来自 ASP.NET Core Web API 的 Angular 重定向在共享部署中不起作用。我使用 ASP.NET Core 7 作为 Web API。当前设置与 ASP.NET C 完美配合...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.