.net - Web 应用程序尝试在 ASP.NET MVC4 应用程序中加载 System.Web.Mvc,版本=1.0.0.0

标签 .net asp.net-mvc asp.net-mvc-4 dotnetopenauth

由于某种原因,当我尝试发布到 MVC4 应用程序中的 AccountController 上的 ActionMethods 之一时,它告诉我无法加载 System.Web.Mvc, Version= 1.0.0.0 或其依赖项之一。我不确定为什么当我实际使用运行时版本 4 时它会尝试加载此程序集。

我怀疑引用的程序集之一可能会导致此问题,但我不太确定。我的主要怀疑是 DotNetOpenAuth.Core 因为以下跟踪:

=== Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/tfs/AMS/Main/AMS/AuthServer/ LOG: Initial PrivatePath = C:\tfs\AMS\Main\AMS\AuthServer\bin Calling assembly : DotNetOpenAuth.Core, Version=4.2.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\tfs\AMS\Main\AMS\AuthServer\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/d0b0b808/59620299/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/d0b0b808/59620299/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/tfs/AMS/Main/AMS/AuthServer/bin/System.Web.Mvc.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

当我尝试发布到以下方法时发生异常:

    [HttpPost]
    public ActionResult Login(String username, String password)
    {
        var request = Session[SESSION_KEY] as EndUserAuthorizationRequest;
        if (request != null)
        {
            Guid siteId = Guid.Parse(request.ClientIdentifier);
            Boolean isAuthenticated = this._identityProviderManager.Authenticate(siteId, "FA", username, password);
            if (isAuthenticated)
            {
                var serviceHost = new AuthorizationServerHost();
                var authorizationServer = new DotNetOpenAuth.OAuth2.AuthorizationServer(serviceHost);
                var approvalMessage = authorizationServer.PrepareApproveAuthorizationRequest(request, username, request.Scope);
                return authorizationServer.Channel.PrepareResponse(approvalMessage).AsActionResult();

            }
        }
        return View();
    }

有什么想法吗?

最佳答案

好的,我找到了解决方案。显然我必须将以下内容添加到 web.config 文件中。

  <runtime>
    <!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). -->
    <legacyHMACWarning enabled="0" />
    <!-- When targeting ASP.NET MVC 3, this assemblyBinding makes MVC 1 and 2 references relink
             to MVC 3 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it.
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
         -->
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

希望这对遇到同样问题的其他人有所帮助。

关于.net - Web 应用程序尝试在 ASP.NET MVC4 应用程序中加载 System.Web.Mvc,版本=1.0.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15409722/

相关文章:

html - 调整窗口大小时,所有内容都被压缩而不是显示滚动条

asp.net - MVC4 - View 和 Controller 之间的关系

c# - Entity Framework 6 异步操作和 TranscationScope

c# - 如何创建跨进程工作的类级互斥量

asp.net-mvc - VS 2010 开发工具包。模板

c# - MVC4 SignalR "signalr/hubs"501 未实现错误

asp.net-mvc-4 - 我可以将 UserId 保留在 User.Identity 中吗? MVC4 简单成员(member)制

c# - 在 .NET 应用程序中检查内存的最佳方法?

c# - 使用 XmlSerializer 时如何添加换行符

javascript - 无法读取未定义的 asp MVC Morris Chart 的属性 'match'