gpt4 book ai didi

asp.net - 使用 ssl 和客户端证书上传大文件 (uploadReadAheadSize) 但不希望预读所有数据

转载 作者:行者123 更新时间:2023-12-02 18:36:08 24 4
gpt4 key购买 nike

我尝试搜索互联网/堆栈溢出,但找不到任何适合我的相关答案。

我有一个 asp.net web api2 应用程序(仅使用 ssl)。我试图允许大文件上传(最多 ~36mb),但除非我将 uploadReadAheadSize 更改为预读此大小,否则我会从 IIS 收到错误,指出请求太长。

我不想设置该属性,因为这样我的数据流只有在 IIS 读取完所有内容后才会到达。

我的问题是:如何使用 ASP.NET 托管并使用 ssl(!) 和 Web api 2 进行大文件上传,而无需配置大的 uploadreadaheadsize?因为我采取的所有步骤似乎都不够。

uploadReadAheadSize:

Specifies the number of bytes that a Web server will read into a buffer and pass to an ISAPI extension or module. This occurs once per client request. The ISAPI extension or module receives any additional data directly from the client. The value must be between 0 and 2147483647. The default value is 49152.

如果我不设置 uploadReadAheadSize 并尝试通过 ssl 上传大文件,则会出现以下错误:

HTTP Error 413.0 - Request Entity Too Large

Things you can try: The page was not displayed because the request entity is too large.

Most likely causes:

The Web server is refusing to service the request because the request entity is too large. The Web server cannot service the request because it is trying to negotiate a client certificate but the request entity is too large. The request URL or the physical mapping to the URL (i.e., the physical file system path to the URL's content) is too long. Things you can try: Verify that the request is valid. If using client certificates, try:

Increasing system.webServer/serverRuntime@uploadReadAheadSize

Configure your SSL endpoint to negotiate client certificates as part of the initial SSL handshake. (netsh http add sslcert ... clientcertnegotiation=enable)

Verify that the request is valid.
If using client certificates, try:
Increasing system.webServer/serverRuntime@uploadReadAheadSize
Configure your SSL endpoint to negotiate client certificates as part of the initial SSL handshake. (netsh http add sslcert ... clientcertnegotiation=enable)

如果我将预读配置为我想要允许的大小,iis 会允许我的请求:

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" />
...

...
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="37748736">
...

我有一个接收文件的虚拟 Controller

[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);
}
}

我在请求中获得的内容

It is True that i'm bufferless but still IIS already read all the data before this context because of the readahead

最佳答案

为了使用 requestLimits 功能,您需要 set it up on IIS级别第一。

也许您一开始就忘记在 IIS 服务器上安装请求过滤。

HTH

关于asp.net - 使用 ssl 和客户端证书上传大文件 (uploadReadAheadSize) 但不希望预读所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20973540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com