2

i have an asp.net mvc4 application. i have a problem in Global.asax file

demo

the 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);
        }
    }
}

when i launch the application i got this error:

demo2

translated to english

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

So what is the issue and how can i fix it?

4

1 回答 1

5

This error is thrown when IIS Express fails to load any library that contains the requested class, in this case integration_finale.MvcApplication. The fact that it can't find the library can have many causes, here, here and here a few are named.

IIS Express adds a whole new layer of confusion to this. The first application you register with IIS Express for a given port, gets its project path registered. When you rename a project or run a new project configured with an earlier-registered port, IIS Express will happily start serving from the wrong directory. This is especially funny when you have identical projects (say, a DEV and a ACC branch, so the library containing a web application with the same name can be found), as the things you see in the browser aren't what you expect them to be.

Open your My Documents\IISExpress\config\appplicationhost.config, and do a search for the port configured for the web application giving the error. You'll see a section like this:

<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>

Check the application section and verify physicalPath is pointing to your current project. Every request to that port is served from that physicalPath, given the virtualDirectory is met (it is in this and most cases, as there is only one virtual directory, starting at the root of the site).

If you rename a project directory, or have two projects using the same port, stuff breaks with IIS Express. Possible fixes:

  • Just change your web project's port used for IIS Express in VS's properties window. This will create a new IIS Express site.
  • Click "Create Virtual Directory" button in your project's configuration. This usually works after a rename, but not after copy.
  • Modify IIS Express' configuration (of course, make a backup). You can rename the site when required and correct the physicalPath of the virtualDirectory.
于 2013-11-11T11:05:17.180 回答