ASP.Net MVC3安全升级导致程序集从3.0.0.0变为3.0.0.1

来源:转载

一直以来,开发MVC3应用,在部署的时候为了方便,并不在用户环境安装MVC3,只是把用到的几个assembly直接部署到bin里,包括:

  • Microsoft.Web.Infrastructure.dll

  • System.Web.Helpers.dll

  • System.Web.MVC.dll

  • System.Web.WebPages.Deployment.dll

  • System.Web.WebPages.dll

  • System.Web.WebPages.Razor.dll

最近系统升级,再这么部署网站时,发现不好用了,报错:

Compiler Error Message:CS1705: Assembly 'TestUnsafe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

发现没?System.Web.MVC的版本要求是3.0.0.1,而bin里放的仍然是3.0.0.0,肯定跑不起来。OK,换个新的程序集上去,把System.Web.MVC.dll 3.0.0.1版放上去,仍然跑不起来,报错:

Parser Error Message:Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.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)

这是由于Web.config未更新导致的,找到下面的几行:

<runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" /></dependentAssembly></assemblyBinding></runtime>

调整oldVersion和newVersion,改成:

<runtime><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.1" /></dependentAssembly></assemblyBinding></runtime>

看到没?把旧版本的MVC统一映射到3.0.0.1版去。再访问站点,一切正常了。

分享给朋友:
您可能感兴趣的文章:
随机阅读: