C# 如何解码使用 MVC 的 Url.Encode(string url) 编码的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2342715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I decode a URL that was encoded with MVC's Url.Encode(string url)
提问by bradjive
I'm surprised the UrlHelper provides an encoder but not a decoder! Does anyone have the code for decoding or know where to find it in the MVC framework?
我很惊讶 UrlHelper 提供了编码器而不是解码器!有没有人有解码的代码或知道在 MVC 框架中在哪里可以找到它?
采纳答案by Yuriy Faktorovich
回答by user677686
An encoded url will automatically be decoded when passed into a controller action. For example:
当传递到控制器动作时,编码的 url 将自动解码。例如:
public ActionResult Index(string url)
{
//url will be decoded here
}
回答by Donuts
Actually it should be HttpUtility.UrlDecode, not HttpServerUtility.
实际上它应该是HttpUtility.UrlDecode,而不是HttpServerUtility。
回答by naveen
HttpUtility.UrlDecode(Parameter);
回答by HamedH
In ASP MVC Core use this:
在 ASP MVC Core 中使用这个:
WebUtility.UrlDecode(string encodedValue)