问题
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