Jim Jeffries
Jim Jeffries

Reputation: 10081

No type was found that matches the controller named 'help'

I have been following this guide to add a help page to document my Web API project. My Controller is named HelpController and I have a route that I am trying to use to map the Index action to /Help. This is the only MVC controller in the project. Because the rest are Web API controllers, we removed the "/api" prefix from the default route in WebAPIConfig.cs.

The HelpController:

public class HelpController : Controller
{
    public ActionResult Index()
    {
        var apiExplorer = GlobalConfiguration.Configuration.Services.GetApiExplorer();
        return View(apiExplorer);
    }
}

And route config:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "help",
            defaults: new { controller = "Help", action = "Index"});

    }
}

In Global.asax.cs

protected void Application_Start()
{
  // ..
  WebApiConfig.Register(GlobalConfiguration.Configuration);
  RouteConfig.RegisterRoutes(RouteTable.Routes);
  // ..
}

But when I try to navigate to /help in the browser I get the following error message.

<Error>
  <Message>No HTTP resource was found that matches the request URI 'http://localhost/ws/help'.</Message>
  <MessageDetail>No type was found that matches the controller named 'help'.</MessageDetail>
</Error>

EDIT: The message contains /ws/help as the application is hosted at localhost/ws in IIS.

Does anyone know what could be causing ASP.NET to not find my HelpController?

UPDATE: If I change the order of RouteConfig and WebApiConfig registration calls in Application_Start I get a 404 instead.

protected void Application_Start()
{
  // ..
  RouteConfig.RegisterRoutes(RouteTable.Routes);
  WebApiConfig.Register(GlobalConfiguration.Configuration);
  // ..
}

Upvotes: 3

Views: 9271

Answers (4)

greg
greg

Reputation: 1873

This answer does not apply directly to OPs question, but it does produce the same error

Your controller's type name needs to end with the word 'Controller', case non-sensitive.

https://learn.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

Reading this doc, you will see that it adds the word 'controller' to the url segment that identifies the controller.

Starting a new project after some time off... that tripped me up. You would think VS might offer a kind word, but it doesnt.

hope it helps.

Upvotes: 0

M_Idrees
M_Idrees

Reputation: 2172

I was getting the same error:

Error><Message>No HTTP resource was found that matches the request URI 'http://localhost:53569/api/values'.</Message><MessageDetail>No type was found that matches the controller named 'values'.</MessageDetail></Error>

By default when I created new controller in asp.net web forms application, it was like this:

ValuesController1 : ApiController

I just simply removed "1", and make it:

ValuesController : ApiController

And it works, don't know if it is a bug or whatever, but it made big trouble for me.

Upvotes: 0

John
John

Reputation: 3546

I had this same error today.

<Error>
  <Message>No HTTP resource was found that matches the request URI 'xxx'.</Message>
  <MessageDetail>No type was found that matches the controller named 'xxx'.</MessageDetail>
</Error>

In my case after 2 days of debuging I finally solved it by setting the microsoft report viewer dll to "Copy to local". Makes no sense to me how it could be related, but maby this will help someone.

Upvotes: 1

Kiran
Kiran

Reputation: 57969

The request for help is being matched by Web API's route as you have removed api from its route template. if a request matches a route, further probing is not done on rest of the routes. You probably have the default order in Global.asax where Web API routes are registered first and then the MVC routes. Could you share how your Global.asax looks like?

EDIT: Based on your last comment, if you install HelpPage nuget package, make sure that the order in your Global.asax looks like this:

AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);

Upvotes: 6

Related Questions