C# ASP.NET Web Api在本地工作,但在IIS7上部署后不工作

C# ASP.NET Web Api在本地工作,但在IIS7上部署后不工作,c#,asp.net,asp.net-web-api,C#,Asp.net,Asp.net Web Api,我的Web Api项目在本地机器上运行得很好,但在我将其部署到文件系统并将其复制到windows server 2008-IIS7之后,我在尝试访问RESTful服务时遇到了此异常 Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located as

我的Web Api项目在本地机器上运行得很好,但在我将其部署到文件系统并将其复制到windows server 2008-IIS7之后,我在尝试访问RESTful服务时遇到了此异常

Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace: 


[FileLoadException: Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   HappyOrder.WebApi.WebApiApplication.Application_Start() +0

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12601933
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12618980
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12458597

这是在我安装了Nuget软件包Microsoft.AspNet.WebApi.Cors之后发生的,首先它在本地甚至不工作,但后来我设法让它与Nuget软件包管理器命令“Update Package”一起工作。

请使用此命令在服务器中重新安装ASP.Net

aspnet_regiis.exe-i


这将正确设置ASP.net并使其正常工作

您只需安装该软件包:

 Install-Package Microsoft.AspNet.WebApi -Version 5.2.3

或者您收到错误的版本。

您可能应该检查服务器中安装的.Net版本以及ASP.Net版本。这绝对是IIS应用程序池中的框架设置。您是如何部署它的?您确定您的
bin
目录包含列出的程序集吗?@Thanigainathan:.Net服务器上的版本是4.5.2,asp.Net目标是4.5,asp.Net版本是5.2.3。0@Kamo:是的,bin目录中列出了一些程序集,我是这样部署的:1.)通过vs2015发布RESTful服务2.)通过远程桌面文件上载到服务器,首先删除旧文件,然后用新发布的文件替换它们如果不想更改已发布服务器的所有ASP.NET版本,应使用什么命令?我不是唯一在这台机器上工作的人。我们可以尝试其他选择。是否已将此dll的副本本地设置为true?