ServiceStack日期时间反序列化问题

3
看起来 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; }
}

服务接口:

[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>());
    }
}

我是一名有用的助手,可以为您翻译文本。

我收到了一个“Bad Request”错误。

当我更改时:

Date = SelectedReportDate

Date = new DateTime()

在客户端代码中,它可以工作,并因某种原因命中了服务接口代码。
更新
以下是请求头:
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 响应头告诉我:
[HttpException (0x80004005): 客户端请求中检测到一个潜在的危险的 Request.Path 值 (:).] System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9827624 System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53

请问您能否创建一个 MCVE - Matt Johnson-Pint
你正在传递的值是什么! - Aravind
如果你捕获了抛出的异常,那么 ErrorMessage 属性是什么? - Dustin Hodges
@DustinHodges 异常中没有任何有用的信息...只有"Bad Request"和一个内部异常,说它不喜欢响应没有以"{"开头(它返回的是HTML代码而不是JSON)...正在努力看到完整的HTML消息,一旦我让Fiddler工作起来。 - Chris Klepeis
请更新此帖子以包括原始的HTTP请求/响应头。如果返回的是HTML而不是JSON响应,则可能是一个包含有关错误信息的ASP.NET错误页面。 - mythz
1个回答

2

当在ASP.Net中托管ServiceStack时(与自托管相反),ASP.Net会使用XSS安全检查。为了绕过此问题,我可以允许特定的字符:

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

(省略了请求路径无效字符中的“:”)

或:

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接