Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Urlhelper.action对一些特殊字符进行编码_C#_Url_Asp.net Core_Urlencode_Asp.net Core Webapi - Fatal编程技术网

C# Urlhelper.action对一些特殊字符进行编码

C# Urlhelper.action对一些特殊字符进行编码,c#,url,asp.net-core,urlencode,asp.net-core-webapi,C#,Url,Asp.net Core,Urlencode,Asp.net Core Webapi,我有一个ASP.Net核心web api。 我使用IUrlHelper.Action生成完全限定的URL。 当我经过时 Østjylland-副本%* 它避开了Ø和空格,但没有避开* %C3%98stjylland%20-%20副本* 根据文件 不应转义任何字符。为什么会发生这种情况?我真的必须使用WebUtility首先从UrlHelper解码url,然后用WebUtility再次编码以转义所有特殊字符吗?类似的回答对我来说很有用 public static MvcHtmlString Ac

我有一个ASP.Net核心web api。 我使用IUrlHelper.Action生成完全限定的URL。 当我经过时

Østjylland-副本%*

它避开了Ø和空格,但没有避开*

%C3%98stjylland%20-%20副本*

根据文件

不应转义任何字符。为什么会发生这种情况?我真的必须使用WebUtility首先从UrlHelper解码url,然后用WebUtility再次编码以转义所有特殊字符吗?

类似的回答对我来说很有用

public static MvcHtmlString ActionNoEscape(this HtmlHelper html, string actionName, string controllerName, object values)
{
    RouteValueDictionary routeValues = new RouteValueDictionary(values);
    UrlHelper urlHelper = new UrlHelper(html.ViewContext.RequestContext, RouteTable.Routes);
    string url = urlHelper.Action(actionName, controllerName);
    url += "?";
    List<string> paramList = new List<string>();
    foreach (KeyValuePair<string, object> pair in routeValues)
    {
        object value = pair.Value ?? "";
        paramList.Add(string.Concat(pair.Key, "=", Convert.ToString(value, CultureInfo.InvariantCulture)));
    }
    url += string.Join("&", paramList.ToArray());
    return new MvcHtmlString(url);
}
public static MvcHtmlString ActionNoEscape(此HtmlHelper html、string actionName、string controllerName、对象值)
{
RouteValueDictionary routeValues=新的RouteValueDictionary(值);
UrlHelper UrlHelper=新的UrlHelper(html.ViewContext.RequestContext,RouteTable.Routes);
字符串url=urlHelper.Action(actionName,controllerName);
url+=“?”;
List paramList=新列表();
foreach(RouteValue中的KeyValuePair对)
{
对象值=对。值??“”;
Add(string.Concat(pair.Key,“=”,Convert.ToString(value,CultureInfo.InvariantCulture));
}
url+=string.Join(&),paramList.ToArray();
返回新的MvcHtmlString(url);
}
当然,我是在.NETFramework中工作的,但是.NETCore的概念应该是相同的。希望这有帮助

他的回答对我有用。希望这有帮助!