1

I'd like to have a ApiController that has an action with a URI or URL parameter.

http://testserver/api/Controller?id=http://www.stackoverflow.com

I implemented actions like:

public bool Get(string id)
{
  ...
}

or

public bool Get(Uri id)
{
  ...
}

However: Whenever I call the URL as stated above, I get an 400 - Error - Bad Request.

2 Answers 2

2

I am unable to reproduce the problem you are describing. This should work. Here are the steps I have tried:

  1. Create a new ASP.NET MVC 4 application using the Empty template
  2. Add an Api controller:

    public class ValuesController : ApiController
    {
        public HttpResponseMessage Get(Uri id)
        {
            return Request.CreateResponse(HttpStatusCode.OK, id);
        }
    }
    
  3. Run the application and navigate to /api/values/?id=http%3A%2F%2Fwww.stackoverflow.com

  4. The id parameter is correctly bound to the Get action argument

So could you provide the steps allowing us to reproduce the problem?

Sign up to request clarification or add additional context in comments.

1 Comment

Ah! That's a Problem of the "Cassini" Visual Studio Webserver. As soon as I ran it in IIS Express it worked ;-)
0

The problem seems to be that I used "Cassini", the VS integrated webserver. As soon as I ran it in IIS Express, it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.