Keep url encoded while using URI class

最后都变了- 提交于 2019-11-27 23:47:10

There is report about that on Microsoft connect. By default escaped slashes not allowed due to security reasons.

http://connect.microsoft.com/VisualStudio/feedback/details/94109/

Cites from there:

I try to use the LinkedIn api, for which I need the following link: http://api.linkedin.com/v1/people/url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fyourlinkedinname:public

As you can see the url field needs to be escaped. How to solve this?

Answer:

We currently don't allow escaped slashes and dots to appear in the path because this is a common way to attacker a server when the URI scheme supports path compression.

But there is tab with workarounds. One of them for .NET 4 is to add app.config:

For .NET 4.0, you can control this through the config file:

http://msdn.microsoft.com/en-us/library/bb882619.aspx

http://msdn.microsoft.com/en-us/library/ee656539.aspx

<configuration>
<uri>
    <schemeSettings>
     <clear/>
     <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
    </schemeSettings>
</uri>
</configuration>

For .NETs before .NET was constructor for Uri class with parameter "dontEscape". For .NET 4 it's obsolete.

What happens if you double escape it?

http://api.linkedin.com/v1/people/url=http%253a%252f%252fwww.linkedin.com%252fin%252fiftachragoler
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!