【发布时间】:2019-11-08 08:38:22
【问题描述】:
我想写一个 WebContentTypeMapper 来返回 uri 路径上的 WebContentFormat 依赖。
直到现在我使用HttpContext.Current.Request.PathInfo。
但如果有超过 64k 正文的大型 POST 请求,则 HttpContext.Current 为空。
我发现 HttpContext.Current 不打算在那里使用。但它适用于所有其他情况,即请求只有一些 kb 小。
有没有其他方法可以在GetMessageFormatForContentType()中找出当前请求的路径?
public class RawContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
string pathInfo;
try
{
pathInfo = HttpContext.Current.Request.PathInfo;
}
catch (NullReferenceException e)
{
// This happens for large POST requests
pathInfo = ...please help!
}
switch (pathInfo)
{
case "/abc/path1":
case "/abc/path2":
return WebContentFormat.Raw;
default:
return WebContentFormat.Default; // No change to default behavior
}
}
}
【问题讨论】:
-
你有没有试过扩展IIS manager->Configuration editor->system.webServer/serverRuntime/uploadReadAheadSize的值?因为这个值的限制是46k左右
-
我不知道。它的默认值为 49152。
标签: c# web-services iis