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

时间:2013-03-14 12:47:44

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

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

我怀疑其中一个引用的程序集可能会导致此问题,但我不确定。我的主要嫌疑人是DotNetOpenAuth.Core,原因如下:

  

===预绑定状态信息===日志:用户= NT AUTHORITY \ NETWORK SERVICE LOG:DisplayName = System.Web.Mvc,Version = 1.0.0.0,   Culture = neutral,PublicKeyToken = 31bf3856ad364e35(完全指定)   日志:Appbase = file:/// C:/ tfs / AMS / Main / AMS / AuthServer / LOG:Initial   PrivatePath = C:\ tfs \ AMS \ Main \ AMS \ AuthServer \ bin调用程序集:   DotNetOpenAuth.Core,Version = 4.2.0.0,Culture = neutral,   公钥= 2780ccd10d57b246。   ===日志:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:   C:\ tfs \ AMS \ Main \ AMS \ AuthServer \ web.config日志:使用主机   配置文件:   C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ aspnet.config日志:   使用来自的机器配置文件   C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ CONFIG \ machine.config中。   日志:后策略引用:System.Web.Mvc,Version = 1.0.0.0,   Culture = neutral,PublicKeyToken = 31bf3856ad364e35日志:正在尝试   下载新的URL   文件:/// C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary   ASP.NET文件/ root / d0b0b808 / 59620299 / System.Web.Mvc.DLL。日志:   试图下载新的URL   文件:/// C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary   ASP.NET   文件/根/ d0b0b808 / 59620299 / System.Web.Mvc / System.Web.Mvc.dll程序。日志:   试图下载新的URL   文件:/// C:/tfs/AMS/Main/AMS/AuthServer/bin/System.Web.Mvc.DLL。警告:   比较程序集名称导致不匹配:主要版本   错误:无法完成程序集的设置(hr = 0x80131040)。探测   终止。

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

    [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();
    }

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

好的,我找到了解决方案。显然我必须将以下内容添加到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>

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