ASP.NETCore(.NETCore)中使用UrlDecode和UrlEncode方法
作者:三味书屋 来源: 2021/11/22 11:06:42

1、.NET Core 1.1中使用

在.NET Core 1.1中使用UrlDecode和UrlEncode方法,可能需要安装Nuget包,安装方法如下,

PM> Install-Package Microsoft.AspNetCore.WebUtilities -Version 2.1.1

命令空间:System.Net.WebUtility

public static class WebUtility {
    public static string UrlDecode(string encodedValue);
    public static string UrlEncode(string value);
}

使用方法

WebUtility.UrlDecode(code)
WebUtility.UrlEncode(code)

2、.Net Core 2.0中使用

在Net Core 2.0中,WebUtility类和下面的两种方法都可以直接使用,不需要安装NuGet包。

1)命名空间:using System.Text.Encodings.Web;

使用方法

UrlEncoder.Default.UrlEncode(code)
UrlEncoder.Default.UrlDecode(code)

2)命名空间:using System.Web;

使用方法

HttpUtility.UrlEncode(code)
HttpUtility.UrlDecode(code)
称      呼:
联系方式:
您的评论:
技术支持:l.w.dong@qq.com www.luweidong.cn
广州市   wx:lwdred
Copyright © 2014 三味书屋 All Rights Reserved
技术支持:l.w.dong@qq.com  sitemap xml  sitemap html

粤公网安备44010602011869号

粤ICP备13031080号-1