0

I had my web api working fine, until a business rule obligates me to change a parameter from int to string. I knew that some bugs where expected but no this one:

    [ResponseType(typeof(UserDTO))]
    [HttpGet]
    [Route("api/users/{id}")]
    public IHttpActionResult GetUser(string id)
    {
        try
        {
            userValidator.secure(Request);
            User user = userValidator.GetUser(id);
            UserDTO userDTO = new UserDTO()
            {
                UserId = user.UserId,
                Name = user.Name,
                Admin = user.Admin,
                Deleted = user.Deleted
            };
            return Ok(userDTO);
        }
        catch (NotExistException exception)
        {
            return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception.Mymessage));
        }
        catch (System.Data.SqlClient.SqlException)
        {
            return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "VecinosUY no se puede conectar a la base de datos (∩︵∩)"));
        }
        catch (Exception exception) {
            return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message));
        }

    }

HTTP get works fine if the string {id} doesn't contains a '.'

http://192.168.0.110:45455/api/users/facu works http://192.168.0.110:45455/api/users/facu.facu don't.

any work around for this problem ?

Facundo Laxalde
  • 305
  • 5
  • 18
  • 1
    What's the purpose of those links? :) Take a look here, I think it's already answered: http://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287 (Danny Varod's answer is probably the best depending on requirements) – Aaron Apr 28 '17 at 19:58
  • Hi Aaron, I know those links only work for me but the idea was give as much info as I can ! btw the other solution worked !!! thanks a lot ! – Facundo Laxalde Apr 28 '17 at 20:09
  • 2
    Possible duplicate of [Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287](http://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287) – Nkosi Apr 29 '17 at 11:47
  • I solve this using https://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287 – Facundo Laxalde Oct 20 '17 at 04:43

0 Answers0