简体   繁体   中英

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:

{"{"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:

{"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. 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 .

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

However, your .NET Core API accept a json object with the following structure:

{
  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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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