I am trying to implement an Options method in a controller of my web service that will return a message containing the valid HTTP methods for the URI endpoint associated with the controller. My Options method looks something like this:
public HttpResponseMessage Options()
{
var resp = new HttpResponseMessage();
resp.Content = new StringContent("");
var apiExplorer = GlobalConfiguration.Configuration.Services
.GetApiExplorer();
foreach (ApiDescription api in apiExplorer.ApiDescriptions)
{
resp.Content.Headers.Add("Allow", api.HttpMethod.Method);
}
return resp;
}
I have tried the above method in a brand-new Web Api project (implication: unaltered routing) inside of a controller with Get, Post, and Delete methods. As expected, a response with "Allow: GET, POST, DELETE" is returned. I am having trouble, however, adding this to a larger project that I am working on. In the larger project, the ApiDescriptions list within ApiExplorer does not contain any elements. Why is this? I suspect it is due to the custom routing that has been implemented, although the only basis for that suspicion is the following link:
http://forums.asp.net/t/1821651.aspx/1
Has anybody else experienced this empty ApiDescription list? If so, did you find a remedy?
Note: I am using MCV 4 RC