Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.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# +;(plus)登录Web API路由_C#_Asp.net Web Api_Asp.net Web Api Routing - Fatal编程技术网

C# +;(plus)登录Web API路由

C# +;(plus)登录Web API路由,c#,asp.net-web-api,asp.net-web-api-routing,C#,Asp.net Web Api,Asp.net Web Api Routing,我正在处理一个asp.NETWebAPI项目,我必须通过帖子传递一个手机号码。但我不能返回加号 我的路线: config.Routes.MapHttpRoute( name: "SmsRoute", routeTemplate: "rest/sms/{country}/{company}/phone/{mobilenumber}", defaults: new { controller = "Sms", action = "PostSms" }); 控制器: publ

我正在处理一个asp.NETWebAPI项目,我必须通过帖子传递一个手机号码。但我不能返回加号

我的路线:

config.Routes.MapHttpRoute( 
    name: "SmsRoute",
    routeTemplate: "rest/sms/{country}/{company}/phone/{mobilenumber}",
    defaults: new { controller = "Sms", action = "PostSms" });
控制器:

public HttpResponseMessage PostSms(string country, string company, string mobilenumber)
{
    return Request.CreateResponse( HttpStatusCode.Created );
}
当我在fiddler上运行此post方法时:

http://index.html/rest/sms/se/company/phone/46700101010/messages/out
我得到的回应是:


但我希望它能显示加号。

+
进行编码:

将您的feedle输入替换为以下输入:

另见:


这是我们在url中添加参数时遇到的常见异常。在这里,您可以了解您的OP是什么,以及在以后的运行中可能需要什么

对于
+
,您可以使用

encodeURIComponent();
为了方便起见,如果您想在url中添加任何特殊字符,如
,只需在web.config中设置属性
relaxedUrlToFileSystemMapping

<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />

IIS阻止加号出现在URL路径元素中

要禁用此功能,请在
web.config
中:

<system.webServer>
    <security>
        <requestFiltering allowDoubleEscaping="true" />
    </security>
</system.webServer>


谢谢您的提示,但它不是编码使用给定示例时会发生什么?编码在查询字符串中有效,但在URL路径组件中无效。这是一个WebAPI问题。
relaxedUrlToFileSystemMapping
禁止的字符列表是
,:,", /, \, |, ? 和*
requestPathInvalidCharacters
的默认值是
,*,%,&,:,\,?
。据我所知,这两个都对加号没有任何影响。
<system.webServer>
    <security>
        <requestFiltering allowDoubleEscaping="true" />
    </security>
</system.webServer>