c# - +(加号)登录 Web API 路由

标签 c# asp.net-web-api asp.net-web-api-routing

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

我的路线:

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

Controller :

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

我收到这样的回复:

enter image description here

但我希望它能够显示加号。

最佳答案

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

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

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

关于c# - +(加号)登录 Web API 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26120919/

相关文章:

c# - 有没有办法告诉路由我的默认操作名称等于 HTTP 操作动词?

c# - 未注册类型的 SimpleInjector 强制 Lifestyle.Transient

c# - ASP.NET Core Web API - 当前上下文 WebApi 中不存在名称 'WebApplication'

asp.net-web-api - 如何为 OData Api 提供自定义媒体类型格式

asp.net-mvc - 如何使用 ASP.NET 5 MVC 6 保护 Web API

c# - 基于查询字符串参数名的路由

asp.net-web-api - 使用 asp.net web api 2 属性路由创建可以在 URI 中接受 DateTime 的路由

c# - 不能将超链接写成字符串

c# - 何时检查对象的状态,一般 OOP,C# 中的示例

c# - OracleCommand.Executenonquery 抛出 'System.InvalidOperationException'