【发布时间】:2013-04-09 06:13:38
【问题描述】:
我正在尝试从 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);
}
}
【问题讨论】:
标签: asp.net-web-api servicestack