加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – 错误请求 – 无效的URL web api

发布时间:2020-12-16 06:49:23 所属栏目:asp.Net 来源:网络整理
导读:我正在使用web-api并且我已将web配置文件设置为接受6144作为url的最大长度,如下所示 system.web compilation debug="true" targetFramework="4.5" / httpRuntime maxUrlLength="6144" relaxedUrlToFileSystemMapping="true" targetFramework="4.5"/ 当我用29
我正在使用web-api并且我已将web配置文件设置为接受6144作为url的最大长度,如下所示

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime maxUrlLength="6144" 
                 relaxedUrlToFileSystemMapping="true"
                 targetFramework="4.5"/>

当我用299个字符调用api时,一切正常,但是超过299个字符会导致错误的请求 – 无效的URL

示例网址:

HTTP://本地主机:56835 / API / multibuys / 10270001C1001034900 | 10358419P4001027620 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 | 10781772P4805004950 |

解决方法

我自己托管web-api时遇到了同样的问题.我猜你所遇到的限制是来自Http.sys的UrlSegmentMaxLength默认值.

要解决此问题,您需要在其下添加新的注册表DWORD

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesHTTPParameters

调用UrlSegmentMaxLength并给出你想要的值:

UrlSegmentMaxLength 260 0 – 32,766 chars Maximum number of characters in a URL path segment (the area between the slashes in the URL). If zero,it is the length that is bounded by the maximum value of a ULONG.

参考文献:
https://serverfault.com/questions/66410/iis-6-on-x64-and-long-urls
http://support.microsoft.com/kb/820129

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读