Global.asax无法找到代码隐藏类

问题描述 投票:5回答:3

当我尝试运行我继承的Web应用程序时,我不断收到此错误。它是在2010年为C#3.5编写的并使用了Mvc 2.我已经安装了必要的库,但是我收到了这个错误。

错误1无法加载类型'AdminConsole.MvcApplication'。 C:\ path \ to \ my \ app \ Global.asax 1

Global.asax.cs看起来像这样:

using System.Web.Mvc;
using System.Web.Routing;

namespace AdminConsole
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}.aspx/{action}/{id}", // URL with parameters
                new { controller = "Entitlement", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}

而Global.asax看起来像这样:<%@ Application Inherits="AdminConsole.MvcApplication" Language="C#" %>

c# asp.net asp.net-mvc visual-studio asp.net-mvc-2
3个回答
9
投票

Codebehind="Global.asax.cs"添加到Markup文件(Global.asax):

从:

<%@ Application Inherits="AdminConsole.MvcApplication" Language="C#" %>

至:

<%@ Application Codebehind="Global.asax.cs"
                Inherits="AdminConsole.MvcApplication" Language="C#" %>

5
投票

验证项目是否已配置为将DLL放入/bin文件夹而不是/bin/x86/Debug/(或类似)。


1
投票

我的问题是我不小心创建了一个网站而不是一个Web应用程序。一旦我重新创建项目,它工作得很好。

© www.soinside.com 2019 - 2024. All rights reserved.