Bad request 400 for HttpUtility.UrlEncoded URL segments

本小妞迷上赌 提交于 2019-12-24 02:34:07

问题


So, if there are url encoded segments in my apps MVC url, IIS throws a BAD REQUEST 400.

e.g. http://u.lasoo.com.au/Offer/*9289--750W-Generic-ATX12V-Power-Supply-%252449dot99/6355

<--- the '*' and '%' are causing this error.

Notice that http://u.lasoo.com.au/Offer/The-Giant-Good-As-Gone-7-Day-Sale/6354 works fine.

What's the correct way to convert an arbitrary string into an accepted MVC URL segment?

UPDATE: the URl segment should resemble the original string. Base64 encoding completely transformed the string.


回答1:


Instead of passing the info in the url you can pass it as a get parameter. Like this:

http://u.lasoo.com.au/Offer/?id=*9289--750W-Generic-ATX12V-Power-Supply-%252449dot99/6355



回答2:


Have you tried UrlEncode? MSDN




回答3:


Try a string replace to strip out or substitute symbols ":", "%", "*", "/" - any symbols illegal within a folder name. They seem to screw up everything royally and appear to be a design weakness of the URL routing system.



来源:https://stackoverflow.com/questions/906754/bad-request-400-for-httputility-urlencoded-url-segments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!