URL Encode and Decode in ASP.NET Core

后端 未结 5 1900
花落未央
花落未央 2020-12-05 03:54
HttpContext.Current.Server.UrlEncode

It\'s only work in .NET Framework. How can I encode or decode uri arguments in ASP.NET Core project?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 04:28

    I'm using a redirect, and UrlEncode did not work for me because it encodes the entire url. I solved this by instead using UriHelper.Encode, shown below.

    UriHelper.Encode

    // generate url string...
    return Redirect(Microsoft.AspNetCore.Http.Extensions.UriHelper.Encode(new System.Uri(url)));
    

提交回复
热议问题