Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

+ (plus) sign in Web API routing

Tags:

I'm working with an asp.net web api project, and I have to pass an mobile number through a post. But i cannot return a plus sign.

my route:

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 ); } 

When I run this post method on fiddler:

http://index.html/rest/sms/se/company/phone/46700101010/messages/out 

I'm getting this response:

enter image description here

But I want it to be able to show me the plus sign.

like image 780
krisal Avatar asked Sep 30 '14 12:09

krisal


People also ask

How does Web API define routing?

Routing is how Web API matches a URI to an action. Web API 2 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web API.

What is difference between attribute and conventional routing?

As per our opinion, Attribute Routing provides us more flexibilities as compared to Convention Based Routing. In Attribute Routing, we can manage route as controller level, action level and also area level. Also, it can override the child route, if required.


1 Answers

IIS prevents plus-signs from being in URL path elements.

To disable this feature, in web.config:

<system.webServer>     <security>         <requestFiltering allowDoubleEscaping="true" />     </security> </system.webServer> 
like image 153
RickNZ Avatar answered Oct 01 '22 14:10

RickNZ