0

We're trying to create our first web api using the .net framework. To try this we've used this demo project: http://www.codeproject.com/Articles/549152/Introduction-to-ASP-NET-Web-API

In this project we've changed the find() function of the AJAX script so it only sends one var to our new democontroller.:

<script>
    var uri = 'api/Demo';
function find() {
        var id = encodeURIComponent($('#prodId').val());
      $.getJSON(uri + '/' + id)
          .done(function (data) {
            $('#product').text(data);
          })
          .fail(function (jqXHR, textStatus, err) {
            $('#product').text('Error: ' + err);
          });
    }
    </script>

The function in this democontroller returns the exact input so we can see that it works:

public class DemoController : ApiController
{
    public IEnumerable<String> Get()
    {
        List<string> bla = new List<string>();
        bla.Add("DEMO!!!");
        return bla;
    }

    public IHttpActionResult Get(string id)
    {
        return Ok(id);
        //return input for test;
    }

}

All the strings we send work perfectly exapt strings which contains a '.' or '%2E' this causes a error: NOT FOUND. This will still happen if we set a static answer.

What can we do to fix this? We are trying to send an email adress so we need the '.'.

dbc
  • 104,963
  • 20
  • 228
  • 340
Quispie
  • 948
  • 16
  • 30
  • Yup, this issue is widely covered in other articles. Personally, I had the same issue when trying to send a date/time in a URL, and the "10.13am" part prevented it from working. My solution was to submit it as "10-23am" in the URL, then replace the minus-sign back to a full-stop on the server. – Mike Gledhill Jun 23 '15 at 14:29

1 Answers1

2

Have a look at this answer MVC4 project - cannot have dot in parameter value?

Try changing the Web.Config file

 <system.web>
      <httpRuntime relaxedUrlToFileSystemMapping="true" />
 </system.web>
Community
  • 1
  • 1
David Votrubec
  • 3,968
  • 3
  • 33
  • 44