.NET Core(C#)html和url字符串编解码方法(HtmlDecode、HtmlEncode、UrlDecode、UrlEncode)
时间:2022-08-05
1、使用UrlEncode和UrlDecode编解码
#if !NETSTANDARD using System.Web; #else using System.Net; #endif using System; namespace UrlHelper { public >UrlHelper { protected string UrlEncode(string value) { var tmp = value; #if !NETSTANDARD return HttpUtility.UrlEncode(tmp, System.Text.Encoding.GetEncoding("utf-8")); #else return WebUtility.UrlEncode(tmp); #endif } public static string UrlDecode(string value) { var tmp = value; #if !NETSTANDARD return HttpUtility.UrlDecode(tmp); #else return WebUtility.UrlDecode(tmp); #endif } } }
2、使用HtmlEncode和HtmlDecode编解码
using System; using System.Net; #if !NETSTANDARD using System.Web; #else #endif namespace HtmlHelpler { public >HtmlHelpler { public static string HtmlDecode(string value) { var tmp = value; #if !NETSTANDARD return HttpUtility.HtmlDecode(tmp); #else return WebUtility.HtmlDecode(tmp); #endif } public static string HtmlEncode(string value) { var tmp = value; #if !NETSTANDARD return HttpUtility.HtmlEncode(tmp); #else return WebUtility.HtmlEncode(tmp); #endif } } }
相关文档:ASP.NET Core(.NET Core)中使用UrlDecode和UrlEncode方法
特别声明:本站部分内容收集于互联网是出于更直观传递信息的目的。该内容版权归原作者所有,并不代表本站赞同其观点和对其真实性负责。如该内容涉及任何第三方合法权利,请及时与824310991@qq.com联系,我们会及时反馈并处理完毕。