简体   繁体   English

C#Web Api长网址无法正常工作

[英]C# web Api Long url Not working

I have the following web API url which is not working 我有以下无法使用的网络API网址

www.localproject.com:843/api/user/validate/eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9eyJ0ZW1wVXJsIjoie1wiQ3VzdG9tZXJJZFwiOjEsXCJDb3Vyc2VJZFwiOjEsXCJUb2tlblwiOm51bGwsXCJFeHBpcnlcIjpcIjIwMTgtMDQtMThUMTc6MzU6MTMuOTQ2MjM2NCswNTowMFwifSJ9uvm7jZ3us5UFa1hqh4bod2cSamcxF2rRUbfxs7DHQs

whenever I hit the above url It gives me following error 每当我碰到上面的URL,它给我以下错误

Bad Request - Invalid URL

HTTP Error 400. The request URL is invalid.

I updated my web.config to this as well but still not working. 我也将我的web.config也更新了,但是仍然无法正常工作。

 <httpRuntime targetFramework="4.6.1" maxRequestLength="20480" maxUrlLength="6144" relaxedUrlToFileSystemMapping="true" />

I also tried editing registry but no luck. 我也尝试编辑注册表,但是没有运气。

How to allow long url using web api? 如何使用Web API允许使用长网址?

By default, HTTP.sys permits 255 segments at a maximum length of 260 characters each. 默认情况下,HTTP.sys允许255个段,每个段的最大长度为260个字符。 That 260 character limit is why you are seeing this issue. 限制为260个字符,这就是您看到此问题的原因。

To fix this you need to make a registry change. 要解决此问题,您需要更改注册表。 Navigate to: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\HTTP\\Parameters 导航到:HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ HTTP \\ Parameters

Add a DWORD value named UrlSegmentMaxLength and set its value to something like 500 or say 1000. 添加一个名为UrlSegmentMaxLength的DWORD值,并将其值设置为500或1000。

While you can probably avoid reboot by restarting the HTTP System Service thru command line is a possibility "net stop http" and "net start http", but because several other services depend upon this service like WWW, Print Spooler, SSDP Discovery etc. I will still recommend rebooting the server. 虽然您可以通过重启命令行来避免通过重启HTTP系统服务来避免重新启动,但是可能会出现“ net stop http”和“ net start http”,但是因为其他一些服务都依赖于此服务,例如WWW,Print Spooler,SSDP Discovery等。仍然建议重新启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM