简体   繁体   English

ASP.NET(网页)=> ASP.NET CORE 3.1 WebAPI

[英]ASP.NET(Web pages) => ASP.NET CORE 3.1 WebAPI

I'm trying to hook up my legacy system with my new Core 3.1 API but the payload that the legacy web app produces doesn't work in my API because all the values are null, but if I test in postman everything works as expected This is the payload from postman: I'm trying to hook up my legacy system with my new Core 3.1 API but the payload that the legacy web app produces doesn't work in my API because all the values are null, but if I test in postman everything works as expected This是来自 postman 的有效载荷:

{"{"UserId":0,"UserGroup":"something","AccessToken":"","CreatedBy":"something","From":"2020/01/01","To":"2020/07/10","TokenName":"something"}
}

And this is from the legacy web app:这是来自旧版 web 应用程序:

{"payload":{"UserId":0,"UserGroup":"soemthing","AccessToken":"","CreatedBy":"something","From":"2020/01/01","To":"2020/07/10","TokenName":"something"}}

As you can notice, the postman payload doesn't include "payload" whereas the legacy does, but the funny thing is that this is supported in the legacy app, meaning I can send the payload as is and the parser will do its job.如您所见,postman 有效负载不包含“有效负载”,而旧版包含,但有趣的是旧版应用程序支持此功能,这意味着我可以按原样发送有效负载,解析器将完成其工作。 So, any clue of what might be happening here?那么,这里可能发生什么的任何线索?

From the information you provided, it seems that the legacy api will produce a json object with a property named payload .从您提供的信息来看,旧版 api 似乎会产生一个 json object ,其属性名为payload

{
  "payload" : { /* the object contains UserId, UserGroup, etc */ }
}

However, your .NET Core API accept a json object with the following structure:但是,您的 .NET 内核 API 接受具有以下结构的 json object:

{
  userId: 0,
  UserGroup: "some group",
  /* other properties... */
}

Therefore you may need to define a binding model with a property named Payload in the .NET Core API:因此,您可能需要在 .NET 核心 API 中定义具有名为Payload的属性的绑定model:

public class LegacyAppBindingModel
{
  public PayloadBindingModel Payload { get; set; }

  public class PayloadBindingModel
  {
    public int UserId { get; set; }
    /* other properties i.e. UserGroup, AccessToken, etc. */
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM