简体   繁体   中英

MVC Routing is Trying to Route on Virtual Directory

I just started a new C# MVC program. I have a ton of these that work, but this one does not and I cannot quite figure out why.

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

    routes.MapRoute(
        name: "Default",
        url: "{action}",
        defaults: new { controller = "Account", action = "LogOn" }
    );

}

It gives me this error:

System.Web.HttpException (0x80004005): The controller for path '/VIRTUALDIRECTORY' was not found or does not implement IController.
   at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
   at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
   at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Like my other sites, this is setup in a Virtual Directory through Visual Studios. Specifically I have it set to "Don't open a page", "Local IIS", with just a typical URL: http://localhost/VIRTUALDIRECTORY

I clicked on Create and it did, there is VIRTUALDIRECTORY in IIS with (what seems at least) to be the same settings as my other virtual directories.

The only difference with this program compared to others is that I am essentially copying a VB.NET MVC program to C#. So I created an empty C# MVC program, then copied and converted the classes. There are (obviously) no compile errors, but I'm sure there's a setting or something that I haven't figured out that's causing this.

Does anyone else know how to solve this?

I am referencing the latest MVC (5.2.3) via nuget.

Not sure if this would apply to anyone else or not, but the problem was a bonehead code issue on my part.

I had split up my Controller into multiple "partial" classes and during the code conversion process none of them were marked "public".

Doh!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM