asp.net-mvc - Asp.net mvc 4 部署错误

标签 asp.net-mvc deployment

我在 mvc 4 中开发了一个 web 应用程序。在开发机器上一切正常,但是在实时服务器上它给了我以下错误。

无法加载文件或程序集

'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.



我尝试了以下解决方案:
  • 将 dll 文件从我的本地驱动器复制到 bin 文件夹
  • 检查我的主机是否启用了 asp.net 4
  • 已检查 web.config 文件是否已正确配置。

  • 这是确切的屏幕跟踪。请注意,最后一行显示了 .net 版本 4 以及 asp.net 版本 4,所以我认为这不是问题。请指导我。
    Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.
    
    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.BadImageFormatException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.
    
    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=4.0.0.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: 
    
    
    [BadImageFormatException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.]
       innovationtimes.MvcApplication.Application_Start() +0
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
    

    这是整个 web.config 文件
     <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <appSettings>
        <add key="webpages:Version" value="2.0.0.0"/>
        <add key="webpages:Enabled" value="false"/>
        <add key="PreserveLoginUrl" value="true"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
      </appSettings>
      <connectionStrings>
        <!--<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=pc1\SQLEXPRESS;Initial Catalog=itdb;User Id=sa;Password=12345;"/>-->
    
      </connectionStrings>
      <system.web>
        <customErrors mode="Off"></customErrors>
        <compilation debug="true" targetFramework="4.0"/>
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers"/>
            <add namespace="System.Web.Mvc"/>
            <add namespace="System.Web.Mvc.Ajax"/>
            <add namespace="System.Web.Mvc.Html"/>
            <add namespace="System.Web.Routing"/>
            <add namespace="System.Web.WebPages"/>
          </namespaces>
        </pages>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
          <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
        </handlers>
      </system.webServer>
    </configuration>
    

    最佳答案

    我终于设法完成了。希望它也能帮助那些有类似问题的人。

    罪魁祸首是发布向导。我使用发布工具发布了我的项目。但是,当我上传已发布的项目时,它根本无法工作并显示 system.web.http 程序集已损坏。

    我是怎么解决的——

    我从我的项目的 bin 文件夹上传了 system.web.http dll 来覆盖发布向导的 dll。

    我被进一步提示输入其他 dll,我对所有这些 dll 都做了同样的事情。

    一旦我用我的 bin 文件夹中的一个替换了所有错误的 dll,该应用程序就开始工作。

    我不确定这是否是 Visual Studio 发布向导的错误。如果有人对此问题有更好的想法,请在此处发布以帮助他人。

    关于asp.net-mvc - Asp.net mvc 4 部署错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13934432/

    相关文章:

    c# - Microsoft 图表、MVC 3 和 Razor

    javascript - 返回包含 javascript 的部分 View 是不好的做法吗?

    deployment - 如何在 Cloud Foundry 中访问用户提供的环境变量?

    .net - 开发时我应引用哪个版本的 Crystal Reports(32 位或 64 位)?

    azure - ARM部署: Get Azure Function API Key

    jquery - 使用 jquery post for mvc 3 在部署时不起作用

    asp.net-mvc - 指定名称和 ID 下拉 Razor 技术 asp dot net mvc4

    asp.net-mvc - 如何使用 HTML.ActionLink 插入图像?

    deployment - 将域指向我的远程 Node JS 应用程序?

    Angular 2 一次构建,随处部署