I am having trouble using the DefaultHttpControllerSelector and HttpConfiguration classes. Take a look at the simple example code below.
I am trying to create a DefaultHttpControllerSelector that will select the correct controller based on the configuration. However, I keep getting an HttpResponseException.
The HttpResponseException object has Response object with fields:
ReasonPhrase = "Not Found"
StatusCode = NotFound
What am I missing here?
////////////////////////////////
Code:
DefaultHttpControllerSelector dhcs = null;
try
{
var myConfig = new HttpConfiguration();
myConfig.Routes.MapHttpRoute(
name: "Main",
routeTemplate: "protected/main/",
defaults: new { controller = "page", page = "main" }
);
myConfig.EnsureInitialized();
dhcs = new DefaultHttpControllerSelector(myConfig);
var request = (new HttpRequestMessage(HttpMethod.Get, "https://localhost:44300/protected/main/"));
var selected = dhcs.SelectController(request);
} catch (HttpResponseException e)
{
var errorResponse = e.Response;
}