ASP.NET Core 中的 URL 编码和解码

2023-12-26

HttpContext.Current.Server.UrlEncode

这仅适用于 .NET Framework。如何在 ASP.NET Core 中对 URI 参数进行编码或解码?


  • 对于 ASP.NET Core 2.0+ 只需添加System.Net命名空间-WebUtility类是作为一部分发送的System.Runtime.Extensionsnuget包,在ASP.NET Core项目中默认引用。

  • 对于以前的版本添加Microsoft.AspNetCore.WebUtilitiesnuget 包。

然后WebUtility将为您提供以下课程:

public static class WebUtility
{
    public static string UrlDecode(string encodedValue);
    public static string UrlEncode(string value);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP.NET Core 中的 URL 编码和解码 的相关文章

随机推荐