I have the following code that is throwing an exception(Object reference not set to an instance of an object.) on the line below.
string uri = Url.Route("http://whatever/", new { id = contact.Id });
Anyone know why this does not work? Thanks
public HttpResponseMessage<Product> Post(Product product)
{
_productsRepository.Add(product);
var response = new HttpResponseMessage<Product>(product, HttpStatusCode.Created);
string uri = Url.Route("http://whatever/", new { id = contact.Id });
response.Headers.Location = new Uri(Request.RequestUri, uri);
return response;
}
Noel12345
Member
1 Points
18 Posts
Url.Route method throwing exception
Apr 04, 2012 09:48 PM|LINK
Hi,
I have the following code that is throwing an exception(Object reference not set to an instance of an object.) on the line below.
string uri = Url.Route("http://whatever/", new { id = contact.Id });Anyone know why this does not work?
Thanks
public HttpResponseMessage<Product> Post(Product product) { _productsRepository.Add(product); var response = new HttpResponseMessage<Product>(product, HttpStatusCode.Created); string uri = Url.Route("http://whatever/", new { id = contact.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); return response; }