1

What I have so far (that works)

I have an ASP.Net Web API 2 project. Well, at least that's what I remember creating when I set up the project, I am not sure how to confirm that.

I am using Visual Studio 2017, and .Net Framework version 4.6.

In terms of the API side of things, this is all working great. The API controllers are fine, I can get data, post data, etc.

Just a bit of additional information in case it matters, I have added SignalR to the project which has been configured.

As it may be important, here are my various configuration files:

Global.asax.cs

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

RouteConfig.cs

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

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { action = "Index", id = UrlParameter.Optional }
    );
}

WebApiConfig.cs

public static void Register(HttpConfiguration config)
{
    // Configure Web API to use only bearer token authentication.
    config.SuppressDefaultHostAuthentication();
    config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

    // Web API routes
    config.MapHttpAttributeRoutes();

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}

What I am trying to do (that doesn't work)

However, I want to add a HTML page so the user can view some information (just static HTML stuff, nothing special). So I have created a standard MVC controller with an action like so (and the Index.cshtml view is in the correct Views folder):

public class NotificationsController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

The problem is that this action never gets run (I have a breakpoint).

What I have tried to identify the problem

Now I get at this point, it could be loads of different things, so here is what I have tried so far to debug the issue:

When I access the URL in a browser (e.g. http://localhost:59461/Notifications), I get:

localhost is currently unable to handle this request. HTTP ERROR 500

At first I thought maybe this is a routing issue, however in VS 2017 you can see that a request has failed for this action:

enter image description here

So surely the routing must be working correctly? Unfortunately, clicking the requests only confirms the 500 error and doesn't give any more information about the problem.

The only additional information I can find is in the Windows Event Viewer, in which I get the following error:

Application 'MACHINE/WEBROOT/APPHOST/PROJECTNAME' with physical root 'C:\PATH TO PROJECT FOLDER\' failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', ErrorCode = '0x80070002 : 0.

But I have researched that error a lot and am yet to find a suitable solution or explanation for my problem.

I have also tried adding Application_Error but that isn't throwing any exceptions either.

At this point I don't know how to work out the cause of the problem. The only thing I can think of is that I need to configure something specifically to allow Web API projects to work with MVC controllers, but I can't find anything on that either.

What can I do to debug this problem correctly, and find the cause?

11
  • No, you don't need "special" configuration to run them together. You just need to make sure the routing doesn't conflict. Sounds like you need to pay attention to the Application_Error event and add proper logging to your application. Commented Jan 24, 2018 at 14:19
  • If you just want a static html page, just drop an html file in the root or wherever you want. Since WebApi is still asp.net, it will server up the page without a problem. no need to bring in mvc if you just want a static page. Commented Jan 24, 2018 at 14:25
  • @mason: I do have exception handling configured and it isn't catching anything (it works great for normal code exceptions). And just to be sure that isn't causing problems, I have just removed that completely and the problem is exactly the same still. Shouldn't running this with VS show me any exception that occur during execution? Commented Jan 24, 2018 at 14:26
  • 1
    You really need to create an minimal reproducible example. I'd start from the ground up. Do a new web application, and then start copying over functionality from old application. Test it at each step. You'll be able to figure it out quickly that way. Commented Jan 24, 2018 at 14:30
  • 1
    Just some thoughts: Do you have a HomeController with an Index action? I'm thinking about the "The controller for path '/' was not found or does not implement IController." error. Also - and I know you're not using Kestrel - have you seen this thread? stackoverflow.com/questions/41992280/… Can you compare the IISExpress setup between your working test project and this broken one? Commented Jan 24, 2018 at 14:57

1 Answer 1

1

Urgh... so I solved the problem...

After stumbling across this post, there is a suggestion to delete the .vs folder in the Visual Studio solution folder. After doing this, and rebuilding the solution, it started working.

No idea what is in that folder that causes this problem exactly though, maybe something got corrupted or some sort of caching conflict, who knows...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.