简体   繁体   English

C#-JObject修改了后请求有效负载中的时间戳

[英]C# - JObject modifyied the time stamp in the post request payload

I have this Web Api controller: 我有这个Web Api控制器:

 [Route("api/v1/GitHubEvents/{Id}/")]
    [HttpPost]
    public async Task<HttpResponseMessage> PostGitHubEvent([FromBody]JObject value, long id)
    { ...
      gitHubEventAuthenticator.ValidateSignature(...);
    }

When the Post request comes from machine with different local time than the controller's timezone, the signature validation fails because of mismatch between the original request's time stamp and the time stamp after serialized by the JObject (or anything else from the IIS/Web Api environment). 当Post请求来自本地时间与控制器时区不同的计算机时,签名验证将失败,因为原始请求的时间戳与JObject(或IIS / Web Api环境中的其他任何东西)序列化后的时间戳之间不匹配。

Can you please suggest way to keep the original time stamp without modifying it by the JObject/Environment? 您能否建议一种方法,而不用JObject / Environment修改原始时间戳?

You can try setting DateFormatHandler 您可以尝试设置DateFormatHandler

JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
{
    DateFormatHandling = DateFormatHandling.Unspecified
};

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

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