POSTing JsonObject With HttpClient From Web API

I’m trying to POST a JsonObject using HttpClient from Web API. I’m not quite sure how to go about this and can’t find much in the way of sample code. Here’s what I have so far: var myObject = (dynamic)new JsonObject(); myObject.Data = “some data”; myObject.Data2 = “some more data”; HttpClient httpClient = new HttpClient(“myurl”); … Read more

Difference between ApiController and Controller in ASP.NET MVC

I’ve been playing around with ASP.NET MVC 4 beta and I see two types of controllers now: ApiController and Controller. I’m little confused at what situations I can choose a particular controller. For ex: If I want to return a view then I’ve to use ApiController or the ordinary Controller? I’m aware that the WCF … Read more

Best practice to return errors in ASP.NET Web API

I have concerns on the way that we returns errors to client. Do we return error immediately by throwing HttpResponseException when we get an error: public void Post(Customer customer) { if (string.IsNullOrEmpty(customer.Name)) { throw new HttpResponseException(“Customer Name cannot be empty”, HttpStatusCode.BadRequest) } if (customer.Accounts.Count == 0) { throw new HttpResponseException(“Customer does not have any account”, … Read more

Is there a tag to turn off caching in all browsers? [duplicate]

This question already has answers here: How do we control web page caching, across all browsers? (29 answers) Closed 5 years ago. I read that when you don’t have access to the web server’s headers you can turn off the cache using: <meta http-equiv=”Cache-Control” content=”no-store” /> But I also read that this doesn’t work in … Read more

Pass an array of integers to ASP.NET Web API?

I have an ASP.NET Web API (version 4) REST service where I need to pass an array of integers. Here is my action method: public IEnumerable<Category> GetCategories(int[] categoryIds){ // code to retrieve categories from database } And this is the URL that I have tried: /Categories?categoryids=1,2,3,4 17 s 17 You just need to add [FromUri] … Read more

Best practice to call ConfigureAwait for all server-side code

When you have server-side code (i.e. some ApiController) and your functions are asynchronous – so they return Task<SomeObject> – is it considered best practice that any time you await functions that you call ConfigureAwait(false)? I had read that it is more performant since it doesn’t have to switch thread contexts back to the original thread … Read more

Does IMDB provide an API? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 5 years ago. Improve this question I recently found a movie organizer application which fetches its data from the IMDB database. Does IMDB provide an … Read more

How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. Using the newer ASP.NET Web API, in Chrome I am seeing XML – how can I change it to request JSON so I can view it in the browser? I do believe … Read more