ASP.NetMVC3安全升級導致程式集從3.0.0.0變為3.0.0.1

技術小胖子發表於2017-11-08

一直以來,開發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未更新導致的,找到下面的幾行:

1
2
3
4
5
6
7
8
  <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,改成:

1
2
3
4
5
6
7
8
  <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版去。再訪問站點,一切正常了。




    本文轉自 BoyTNT 51CTO部落格,原文連結:http://blog.51cto.com/boytnt/1590928,如需轉載請自行聯絡原作者


相關文章