我想知道是否有进行更换System.Web.HttpUtility.UrlEncode和UrlDecode。
我发现Encode应该是: Microsoft.Framework.WebEncoders.UrlEncoder.Default.UrlEncode。
但是我没有找到UrlDecode。有一个吗?
Answers:
System.Runtime.Extensions定义UrlDecode和HtmlDecode。
namespace System.Net
{
public static partial class WebUtility
{
public static string HtmlDecode(string value) { return default(string); }
public static string HtmlEncode(string value) { return default(string); }
public static string UrlDecode(string encodedValue) { return default(string); }
public static byte[] UrlDecodeToBytes(byte[] encodedValue, int offset, int count) { return default(byte[]); }
public static string UrlEncode(string value) { return default(string); }
public static byte[] UrlEncodeToBytes(byte[] value, int offset, int count) { return default(byte[]); }
}
}
虽然System.Runtime.Extensions定义了扩展名,但您可以从其代码中注意到,您需要调用的实际类是System.Net.WebUtility
选项1:System.Net.WebUtility
目前,还没有公开作出的计划,包括Decode在Microsoft.Framework.WebEncoders。
用法
System.Net.WebUtility.UrlEncode(myString)
System.Net.WebUtility.UrlDecode(myString)
选项2:System.Text.Encodings.Web.UrlEncoder
这是在asp.net核心服务容器中注册的,可以注入到控制器等中。