Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

DefaultHttpControllerSelector not finding any controller, "Not Found" response

$
0
0

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;
            }


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>