简体   繁体   English

MVC路由尝试在虚拟目录上路由

[英]MVC Routing is Trying to Route on Virtual Directory

I just started a new C# MVC program. 我刚刚开始了一个新的C#MVC程序。 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. 像我的其他站点一样,这是通过Visual Studio在虚拟目录中设置的。 Specifically I have it set to "Don't open a page", "Local IIS", with just a typical URL: http://localhost/VIRTUALDIRECTORY 具体来说,我将其设置为“不打开页面”,“本地IIS”,仅使用典型的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. 我单击创建,然后单击确定,IIS中有VIRTUALDIRECTORY,(至少看起来)与其他虚拟目录的设置相同。

The only difference with this program compared to others is that I am essentially copying a VB.NET MVC program to C#. 与其他程序相比,这个程序的唯一区别是我本质上是将一个VB.NET MVC程序复制到C#。 So I created an empty C# MVC program, then copied and converted the classes. 因此,我创建了一个空的C#MVC程序,然后复制并转换了这些类。 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. 我通过nuget引用了最新的MVC(5.2.3)。

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". 我将我的Controller拆分为多个“部分”类,在代码转换过程中,没有一个被标记为“公共”。

Doh! 卫生署!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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