繁体   English   中英

Global.asax 找不到代码隐藏类

[英]Global.asax can't find code-behind class

当我尝试运行我继承的 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#" %>

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

从:

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

至:

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

确认项目已配置为将您的 DLL 放入/bin文件夹,而不是/bin/x86/Debug/ (或类似文件夹)。

我的问题是我不小心创建了一个网站而不是一个 Web应用程序 一旦我重新创建了项目,它就可以正常工作。

正如@FMM 所写

确认项目已配置为将您的 DLL 放入 /bin 文件夹,而不是 /bin/x86/Debug/(或类似文件夹)。

我可以检查并解决我的问题,更改配置管理器。 然后,将平台从“x86”更改为“Any CPU”。

1 - 配置管理器:

1 - 配置管理器

2 - x86 到任何 CPU:

2 - x86 到任何 CPU

暂无
暂无

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

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