Asp.net 使用ssl和客户端证书(uploadReadAheadSize)时进行大文件上载,但不希望提前读取所有数据
我试图搜索internet/堆栈溢出,但找不到任何适合我的相关答案 我有一个asp.net web api2应用程序(仅使用ssl)。 我正试图允许大文件上传(高达~36mb),但除非我将uploadReadAheadSize更改为readahead这个大小,否则我会从IIS收到一个错误,即请求太长 我不想设置那个属性,因为我的数据流只有在IIS已经全部读取之后才能到达 我的问题是:如何使用asp.net托管并使用ssl(!)和web api 2进行大文件上载,而不配置大的uploadreadaheadsize?因为我所采取的措施似乎都不够 uploadReadAheadSize: 指定Web服务器将读入缓冲区并传递给ISAPI扩展或模块的字节数。这在每个客户端请求中发生一次。ISAPI扩展或模块直接从客户端接收任何附加数据。该值必须介于0和2147483647之间。 默认值为49152 如果我没有设置uploadReadAheadSize并尝试通过ssl上载大文件,则会出现以下错误: HTTP错误413.0-请求实体太大 您可以尝试的事情: 页面未显示,因为请求实体太大 最可能的原因: Web服务器拒绝为请求提供服务,因为请求实体太大。 Web服务器无法为请求提供服务,因为它正在尝试协商客户端证书,但请求实体太大。 请求URL或到URL的物理映射(即指向URL内容的物理文件系统路径)太长。 您可以尝试的事情: 验证请求是否有效。 如果使用客户端证书,请尝试: 增加system.webServer/serverRuntime@uploadReadAheadSize 将SSL端点配置为协商客户端证书,作为初始SSL握手的一部分。(netsh http add sslcert…clientcertnegotiation=enable) 如果我将预读配置为希望允许的大小,iis将允许我的请求:Asp.net 使用ssl和客户端证书(uploadReadAheadSize)时进行大文件上载,但不希望提前读取所有数据,asp.net,.net,iis,asp.net-mvc-5,asp.net-web-api2,Asp.net,.net,Iis,Asp.net Mvc 5,Asp.net Web Api2,我试图搜索internet/堆栈溢出,但找不到任何适合我的相关答案 我有一个asp.net web api2应用程序(仅使用ssl)。 我正试图允许大文件上传(高达~36mb),但除非我将uploadReadAheadSize更改为readahead这个大小,否则我会从IIS收到一个错误,即请求太长 我不想设置那个属性,因为我的数据流只有在IIS已经全部读取之后才能到达 我的问题是:如何使用asp.net托管并使用ssl(!)和web api 2进行大文件上载,而不配置大的uploadreada
C:\Windows\SysWOW64>C:\Windows\System32\inetsrv\appcmd set config ... -section:system.webServer/serverRuntime /uploadReadAheadSize:n /commit:apphost
Applied configuration changes to section "system.webServer/serverRuntime" for "MACHINE/WEBROOT/APPHOST/..." at configuration commit path "MACHINE/WEBROOT/APPHOST"
我在web.config中配置了此选项:
...
<httpRuntime targetFramework="4.5.1" maxRequestLength="36864" />
...
属性和策略:
public class ControllerBufferlessAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings settings,
HttpControllerDescriptor descriptor)
{
settings.Services.Replace(typeof(IHostBufferPolicySelector), new PolicySelectorBufferless());
}
}
public class PolicySelectorBufferless : WebHostBufferPolicySelector
{
public override bool UseBufferedInputStream(object hostContext)
{
return false;
}
public override bool UseBufferedOutputStream(HttpResponseMessage response)
{
return base.UseBufferedOutputStream(response);
}
}
我在请求中获得的内容
的确,我是无缓冲区的,但由于readahead,IIS已经读取了此上下文之前的所有数据
为了实现用户请求限制功能,您需要首先升级 也许你忘了在IIS服务器上安装请求过滤
HTH。然后您的maxRequestLength=“”配置将启动。此链接应该是什么?
...
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="37748736">
...
[ControllerBufferlessAttribute()]
public class UploadController : ApiController
{
public HttpResponseMessage Post([FromUri]string filename)
{
var selector = RequestContext.Configuration.Services.GetHostBufferPolicySelector();
var isbufferless = string.Format("It is {0} that i'm bufferless but still IIS already read all the data before this context because of the readahead", selector is PolicySelectorBufferless);
return new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = isbufferless };
}
}
public class ControllerBufferlessAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings settings,
HttpControllerDescriptor descriptor)
{
settings.Services.Replace(typeof(IHostBufferPolicySelector), new PolicySelectorBufferless());
}
}
public class PolicySelectorBufferless : WebHostBufferPolicySelector
{
public override bool UseBufferedInputStream(object hostContext)
{
return false;
}
public override bool UseBufferedOutputStream(HttpResponseMessage response)
{
return base.UseBufferedOutputStream(response);
}
}