增加asp.net核心中的最大URL长度 [英] Increase max url length in asp.net core

查看:466
本文介绍了增加asp.net核心中的最大URL长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net核心网络api,它启用了tts请求.基本上,您要求http://server.url/Whatever you want it to say.mp3以获得带有tts语音文本的mp3.

I have an asp.net core web api, that enables tts requests. You basically request http://server.url/Whatever you want it to say.mp3 to get an mp3 with the text spoken in tts.

但是问题是,如果我给它传递一个长字符串,它将返回一个400 - The request URL is invalid.似乎服务器正在达到某种形式的最大URL长度限制.我可以找到有关如何解决此问题的信息,这是经典的" asp.net web.config,而不是如何在asp.net核心中解决此问题.

But the problem is, that it will return a 400 - The request URL is invalid if I pass it a long string. It seems like the server is hitting some sort of max URL length limitation. I can find information on how to fix this is the "classic" asp.net web.config, but not how to fix this in asp.net core.

在asp.net核心中增加最大URL长度的正确方法是什么?

What is the correct way of increasing the maximum URL length in asp.net core?

更新:

确切的网址例如:

它是URL编码的.我会尝试找出确切的最大值.

It is URL-encoded. I'll try to figure out what the exact maximum is.

我不能使用POST,因为要利用它的工具仅支持mp3文件的网址(因此,控制器中使用的扩展名为.mp3).

I cannot use a POST, as the tool that is going to make use of this only supports urls for mp3 files (hence the .mp3 extension used in my controller).

更新2

它接受的最长请求包含397个字符,这似乎不太合逻辑.如果再添加一个,它将返回代码400.

The longest request it accepts has 397 characters, which does not seem very logical. If I add one more, it will return a code 400.

更新3

事实证明,仅当将其部署在服务器上(使用IIS),在本地运行时,它才支持更长的字符串(我还没有看到它返回代码400).我必须调查IIS才能找出问题所在.

It turns out to only have this issue when deployed on the server (using IIS), when run locally, it supports way longer strings (I haven't seen it return a code 400 yet). I'll have to look into IIS to see where it goes wrong.

推荐答案

事实证明,我需要两件事来解决此问题:

As it turns out, I needed two things to fix this:

更改web.config

我需要将以下内容添加到web.config中,以指示IIS允许使用更长的URL:

I needed to add the following to the web.config to instruct IIS to allow longer URLs:

<system.webServer>
    <security>
        <requestFiltering allowDoubleEscaping="false">
            <requestLimits maxAllowedContentLength="30000000" maxUrl="40960" maxQueryString="20480" />
        </requestFiltering>
    </security>
</system.webServer>

编辑注册表

此后,由于UrlSegment的长度太长,IIS仍将抛出代码400.遗憾的是,更改此设置的唯一方法是通过一些较小的注册表黑客攻击.

After this, IIS will still throw a code 400, because the UrlSegment length is too long. Sadly, the only way to change this is by some minor registry hacking.

导航到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters并找到键UrlSegmentMaxLength.如果不存在,请使用REG_DWORD的值类型创建一个.我使用1000 HEX(4096 DEC)作为值.如果密钥还不存在,则默认值为260.

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters and find the key UrlSegmentMaxLength. If it is not there, create one with a value type of REG_DWORD. I used 1000 HEX (4096 DEC) as the value. The default value is 260 if the key is not there yet.

在更改生效之前,我需要重新启动服务器.

Before the change was effective, I needed to reboot the server though.

这篇关于增加asp.net核心中的最大URL长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆