Controller not found within a Web forms application

217 Views Asked by At

I have a project where there is a controller within a web forms application.

My controller is called Token

 public class TokenController : BaseTokenController
{
    public override bool IsInherited => true;


}

this controller inherits from BaseTokenController

public abstract class BaseTokenController : ApiController
{
    public abstract bool IsInherited { get; }
    public virtual bool Post([FromBody]TokenValidateArgs args)
    {
        if (!IsInherited)
            throw new Exception("Attempt to call base token controller not allowed");

        return args.Validate();
    }

    public virtual string Get()
    {
        if (!IsInherited)
            throw new Exception("Attempt to call base token controller not allowed");
        return new Token()
    }
}

In my global.asax I have a method called Register:

 public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute("API default", "api/{controller}/{id}",
            new { id = RouteParameter.Optional });

    }

and in global.asax Application_Start the first line of code is

protected void Application_Start(object sender, EventArgs e)
    {
        Register(GlobalConfiguration.Configuration);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

I did have this working, however I then merged with the master branch for the project and it stopped working. I can't see anything that has changed.

this is the error:

No HTTP resource was found that matches the request URI 'https://localhost:44398/api/token'. No type was found that matches the controller named 'token'.

Has anyone else experienced a similar issue and would know how to fix this. I have read other threads and tried to fix this by putting in a RoutePrefix on the controller, moving the order of execution on the global.asax and calling the get() method directly

1

There are 1 best solutions below

0
taylor smith On

So for my issue it turns out the project that has the "BaseTokenController" was running version 5.2.3 of WebApi however the web application project was running 5.2.4 which caused a conflict, resulting in a 404 error. To fix this I downgraded the app to 5.2.3