24

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
krisal
  • 621
  • 6
  • 19

3 Answers3

26

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>
RickNZ
  • 18,448
  • 3
  • 51
  • 66
  • This worked for me and my problem where UTC dates with a positive time zone would fail. (ie: `/Contacts/LastModified/2020-04-06T08:00:00+02:00`) – ThePeter Apr 10 '23 at 20:34
2

This a common anomaly that we face while adding parameters in the url's. Here you can have a hint of what your OP is and what you might need at a later run

You can have many options as for + you can encode in your java script file using

encodeURIComponent();

And also for your ease if you want to add any special characters in your url like a . then simply set the property relaxedUrlToFileSystemMapping in your web.config

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

Or you can just add or remove some of the characters to block/allow using requestPathInvalidCharacters in your web.config

<httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,:,\,?"/>
Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
  • This is a WebAPI question. – Ofiris Oct 01 '14 at 11:00
  • The list of characters forbidden by `relaxedUrlToFileSystemMapping` is `<, >, :, ", /, \, |, ? and *`. The default value of `requestPathInvalidCharacters` is `<, >, *, %, &, :, \, ?`. Neither of those have any effect on plus-signs, as far as I can tell. – RickNZ Jan 30 '15 at 02:50
1

Encode the +:

Replace your feedle input with this one:

http://index.html/rest/sms/se/company/phone/%2B46700101010/messages/out

Also see: AJAX POST and Plus Sign ( + ) -- How to Encode?

http://www.google.com/search?q=foo%2Bbar

Community
  • 1
  • 1
Ofiris
  • 6,047
  • 6
  • 35
  • 58