我正在尝试从 asp.net mvc4 webapi 框架迁移到 servicestack 框架。我在 webapi 中有一个 delegatingHandler 与 servicestack 中的这个等效吗?
这是我将验证我的请求并返回自定义响应的地方,而无需进一步说明。
我的委托处理人
public class xyzDH : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
int maxLengthAllowed = 200;
long? contentLen = request.Content.Headers.ContentLength;
if (contentLen > maxLengthAllowed)
{
var defaultResponse = ResponseHelper.GetBaseResponse("Content Lenght Issue", true, UploadLogSizeIssue);
return Task<HttpResponseMessage>.Factory.StartNew(() =>
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(defaultResponse.ToString(), Encoding.UTF8, "message/http")
};
return response;
});
}
return base.SendAsync(request, cancellationToken);
}
}