The difference is one Encodes Url of string and one encodes Path portion (which means the portion of url before query string) from Url, Here is the implementation how it looks:
/// <summary>Encodes a URL string.</summary>
/// <returns>An encoded string.</returns>
/// <param name="str">The text to encode. </param>
public static string UrlEncode(string str)
{
if (str == null)
{
return null;
}
return HttpUtility.UrlEncode(str, Encoding.UTF8);
}
and here is implementation of UrlPathEncode:
/// <summary>Encodes the path portion of a URL string for reliable HTTP transmission from the Web server to a client.</summary>
/// <returns>The URL-encoded text.</returns>
/// <param name="str">The text to URL-encode. </param>
public static string UrlPathEncode(string str)
{
if (str == null)
{
return null;
}
int num = str.IndexOf('?'); // <--- notice this
if (num >= 0)
{
return HttpUtility.UrlPathEncode(str.Substring(0, num)) + str.Substring(num);
}
return HttpUtility.UrlEncodeSpaces(HttpUtility.UrlEncodeNonAscii(str, Encoding.UTF8));
}
and msdn also states for HttpUtility.UrlEnocde
:
These method overloads can be used to encode the entire URL, including query-string values.