我想编写一个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
}
}
}