gpt4 book ai didi

datetime - ServiceStack DateTime反序列化问题

转载 作者:行者123 更新时间:2023-12-02 01:19:42 26 4
gpt4 key购买 nike

看起来 ServiceStack 不喜欢我在请求中使用 DateTime 属性作为参数。我收到一条“错误请求”消息……异常中没有其他有用的详细信息。内部异常显示 html 代码(被截断),并且只是说“类型定义应以“{”开头,期望序列化类型 'ErrorResponse'...”

在我的客户中:

    private DateTime _selectedReportDate;
public DateTime SelectedReportDate
{
get { return _selectedReportDate; }
set { SetProperty(ref _selectedReportDate, value); }
}
....
var txResults = await ServiceClient.Instance.GetAsync(new PaymentSummaries()
{
Date = SelectedReportDate
});

服务模式:

[Route("/report/paymentsummaries/{Date}", "GET")]
public class PaymentSummaries : IReturn<List<PaymentSummary>>
{
public DateTime Date { get; set; }
}

服务接口(interface):

[Authenticate]
public class PaymentSummariesService : Service
{
public List<PaymentSummary> Get(PaymentSummaries request)
{
var results = Db.SqlList<Data.OrmLite.SpResponse.ReconcilePaymentSummaryRecord>("EXEC [Report].[ReconcilePaymentsSummary] @date", new { date = request.Date });

return results.ConvertAll(x => x.ConvertTo<PaymentSummary>());
}
}

我收到“错误请求”错误。

当我改变时:

Date = SelectedReportDate

Date = new DateTime()

在客户端代码中,它确实有效,并且出于某种原因命中服务接口(interface)代码。

更新

这是请求 header :

GET http://devservicestack:44345/report/paymentsummaries/2016-11-30T13%3A09%3A15.6795974-05%3A00 HTTP/1.1 Accept-Encoding: gzip,deflate Accept: application/json User-Agent: ServiceStack .NET Client 4.54 Host: devservicestack:44345 Cookie: ss-id=F4Bt4aMonhyFQcfqmSmR; ss-pid=K6aJMA17Xw31qIVy1z8V; ss-opt=temp

响应 header 告诉我:

[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9827624
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53

最佳答案

在 ASP.Net 中托管 ServiceStack 时(与自托管相反),ASP.Net 使用 XSS 安全检查。为了解决这个问题,我可以允许特定字符:

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

(在 requestPathInvalidCharacters 中省略了“:”)

或:

  <system.web>
<httpRuntime targetFramework="4.6.2" requestValidationMode="2.0" requestPathInvalidCharacters="" />
</system.web>

禁用整个应用程序的请求验证。

关于datetime - ServiceStack DateTime反序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40875583/

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