ASP.NET Core 中的 URL 编码和解码 [英] URL Encode and Decode in ASP.NET Core
本文介绍了ASP.NET Core 中的 URL 编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HttpContext.Current.Server.UrlEncode
这仅适用于 .NET Framework.如何在 ASP.NET Core 中编码或解码 URI 参数?
This does only work in .NET Framework. How can I encode or decode URI arguments in ASP.NET Core?
推荐答案
对于 ASP.NET Core 2.0+ 只需添加
System.Net
命名空间 -WebUtility
类作为System.Runtime.Extensions<的一部分提供/code> nuget 包,在 ASP.NET Core 项目中默认引用.
For ASP.NET Core 2.0+ just add
System.Net
namespace -WebUtility
class is shipped as part ofSystem.Runtime.Extensions
nuget package, that is referenced by default in ASP.NET Core project.对于以前的版本,添加
Microsoft.AspNetCore.WebUtilities
nuget 包.For the previous version add
Microsoft.AspNetCore.WebUtilities
nuget package.然后
WebUtility
类将可供您使用:Then the
WebUtility
class will be available for you:public static class WebUtility { public static string UrlDecode(string encodedValue); public static string UrlEncode(string value); }
这篇关于ASP.NET Core 中的 URL 编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文