gpt4 book ai didi

asp.net - 如何在 ServiceStack 中传递 DateTimeOffset 值

转载 作者:行者123 更新时间:2023-12-04 04:52:26 25 4
gpt4 key购买 nike

我收到以下消息:

[Route("/devices/{DeviceId}/punches/{EmployeeId}/{DateTime}", "GET,POST")]
public class Punch
{
public string DeviceId { get; set; }
public string EmployeeId { get; set; }
public DateTimeOffset DateTime { get; set; }
public string TimeZoneId { get; set; }
public PunchKind Kind { get; set; }
}

我需要通过一个完整的 DateTimeOffset在日期时间部分...

以下工作完美:
http://localhost:54146/devices/1001/punches/666/2012-04-01
但是,当我尝试传递完整的日期时间偏移数据时,它会失败并显示 HTTP 400 错误:错误请求。到目前为止,我已经尝试了以下相同的错误(即使 URL 编码也没有帮助):
http://localhost:54146/devices/1001/punches/666/2012-04-01T20:59:00.0000000-03:00 http://localhost:54146/devices/1001/punches/666/2012-04-01 20:59:00.0000000-03:00 http://localhost:54146/devices/1001/punches/666/2012-04-0120:59:00.0000000-03:00 http://localhost:54146/devices/1001/punches/666/2012-04-01T20%3A59%3A00.0000000-03%3A00
其他排列都失败并出现相同的错误。

如何将 DateTimeOffset 作为 URL 的一部分传递?

最佳答案

<,>,*,%,&,:\默认情况下,ASP.NET 不允许在 URL 中使用。在您的情况下,冒号是罪魁祸首(是否已编码并不重要)。您可以通过将以下内容添加到您的 Web.config 文件来修复它:

<system.web>
...
<httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\" />
...
</system.web>

引用资料:
  • HttpRuntimeSection.RequestPathInvalidCharacters Property
  • Experiments in Wackiness: Allowing percents, angle-brackets, and other naughty things in the ASP.NET/IIS Request URL
  • 关于asp.net - 如何在 ServiceStack 中传递 DateTimeOffset 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17243687/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com