Think I am going mad here..

So I have a working website setup in IIS. This was all configured by a previous developer. We have a set of reports that you can browse to by going to localhost/Reports/ReportName, the underlying directory structure in IIS is actually Reports/Views/ReportName/index.cshtml. I have added a new report with the exact same setup as the others however when I navigate to the localhost/Reports/NewReportName URL I get a 404 and I am not quite sure what I am missing...

Dani AI

Generated

Good catch from — a missing controller action is a very common cause of a 404 in an MVC site even when the view exists on disk. The routing table only maps URLs to controller actions; if no action matches the incoming URL (or the action is non-public, decorated to disallow GET, or the controller can't be instantiated) IIS will return a 404 before the view is rendered.

Quick checklist to prevent the same trap:

  • Confirm the controller class is public and derives from Controller, and that the action method is public (not static) and named/mapped to the URL you expect (or use [ActionName]).
  • If the action requires POST or has route constraints, make sure a plain GET is still supported for the URL you’re testing.
  • If the controller has constructor parameters, verify those services are registered in your DI container (or provide a fallback/parameterless ctor) — unregistered dependencies can prevent controller creation and produce errors.
  • Ensure no physical file or folder is shadowing the route (IIS will serve a static match instead of letting MVC route it unless routing/modules are configured to handle extensionless requests).

Practical diagnostics to use next time:

  • Check the IIS logs for the 404 substatus (e.g., 404.0 vs 404.2) and enable Failed Request Tracing (FREB) to see whether IIS or MVC produced the 404.
  • Temporarily enable full errors (customErrors off / detailedErrors) on a development box to get the real exception/stack trace.
  • Add simple logging at controller creation and in the action to confirm whether the controller was instantiated and the action invoked.

Minimal example (controller action pattern):

public ActionResult NewReportName()
{
    // prepare model, then render the view
    return View();
}

Also review DI registrations if you hit “injection” errors after adding the action — missing or incorrectly scoped services are the usual culprits.

Recommended Answers

All 8 Replies

Perhaps something special happening in your RouteConfig?

Haven't a clue where the route config is, I can see a RouteConfig.cs class but nothing of interest in it...

Your request should get there, perhaps you can debug/trace from there what happens. No idea otherwise. No rewrite rules set up?

Url rewrite isn't installed on these servers.

Will try and debug the routing stuff

Your missing route definitions. And probably a controller. Show us the content of your RouteConfig.cs and tell us what you have under the controllers folder.

RouteConfig.cs

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

        routes.MapRoute(
            name: "ConfigJs",
            url: "DScripts/Config.js",
            defaults: new { controller = "General", action = "Config" }
        );


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

Under the controllers folder I have
- GeneralController
- ReportControllerBase
- NewReportNameController

and the other existing controllers that all work fine.

The above RouteConfig appears to work for everything else

The route is proper. The problem should be at the controller. There should be methods in your reportscontroller that correspond with the report names. To add a new report you need to add a method with the name as your new report and put the logic to make it find and display the report.

Nailed it Toby.

Was missing some code within the Controller class for the specific report handling certain url actions. Now getting some errors around injection but I can resolve those hopefully. Will mark this as resolved.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.