gpt4 book ai didi

c# - 修复 global.asax 中的语法错误

转载 作者:行者123 更新时间:2023-12-02 21:43:59 24 4
gpt4 key购买 nike

我有一个 ASP.NET MVC4 应用程序。我的 Global.asax 文件有问题

demo

Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace integration_finale
{

public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
}

当我启动应用程序时,我收到此错误:

demo2

翻译成英文

Server Error in '/' Application. Analysis error Description: An error occurred during the analysis of a requirement to meet this demand resource. Please see below the details of the error analysis in question and modify your source file appropriately.

Message Parser Error: Could not load type 'integration_finale.MvcApplication'.

Source Error:

Line 1: <% @ Application Codebehind = "Global.asax.cs" Inherits = "integration_finale.MvcApplication" Language = "C #"%>

Source File: / global.asax Line: 1

Version Information: Microsoft NET Framework Version:. 4.0.30319; ASP.NET Version: 4.0.30319.18056

那么问题是什么以及如何解决它?

最佳答案

当 IIS Express 无法加载任何包含所请求的类的库(在本例中为 integration_finale.MvcApplication)时,会引发此错误。找不到该库的事实可能有多种原因,here , herehere其中一些被命名。

IIS Express 对此又增加了一层全新的困惑。您向 IIS Express 注册给定端口的第一个应用程序将注册其项目路径。当您重命名项目或运行配置了早期注册端口的新项目时,IIS Express 会很高兴地从错误的目录开始提供服务。当您有相同的项目(例如,一个 DEV 和一个 ACC 分支,因此可以找到包含同名 Web 应用程序的库)时,这尤其有趣,就像您在浏览器中看到的那样并不是您所期望的那样。

打开我的文档\IISExpress\config\appplicationhost.config,然后搜索为出现错误的 Web 应用程序配置的端口。您将看到这样的部分:

<site name="YourWebsiteName" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Source\WebsiteProject" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:1234:localhost" />
</bindings>
</site>

检查应用程序部分并验证 physicalPath 是否指向您当前的项目。如果满足 virtualDirectory,则对该端口的每个请求都从该 physicalPath 提供服务(在这种情况和大多数情况下,因为只有一个虚拟目录,从网站的根目录)。

如果您重命名项目目录,或者有两个项目使用同一端口,则 IIS Express 会出现问题。可能的修复:

  • 只需在 VS 的属性窗口中更改用于 IIS Express 的 Web 项目端口即可。这将创建一个新的 IIS Express 站点。
  • 点击项目配置中的“创建虚拟目录”按钮。这通常在重命名后有效,但在复制后无效。
  • 修改IIS Express的配置(当然要做好备份)。您可以根据需要重命名站点并更正 virtualDirectoryphysicalPath

关于c# - 修复 global.asax 中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19903898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com