2016-09-14 24 views
0

我目前正在研究一個Asp.Net MVC web項目。我的項目在3個不同的Web服務器上使用,每個服務器都有自己的SQL數據庫。最近我一直有一個非常惱人的錯誤,沒有傷害任何東西,但浪費我的時間,並讓我拉我的頭髮。ASP.NET MVC煩人的web.config內的bug

只有當我的Web服務器之間切換時出現的問題(即,當我想放棄發佈到站點A和發佈變更到站點B也),或當我進行了更改在web.config文件在我的項目中。

這是看我的連接字符串如何排序在我的web.config。當我需要發佈到站點或通過本地主機測試更改時,我只是簡單地評論當前字符串,然後取消註釋所需的選擇。

的Web.config代碼(服務器C在這裏是用戶)

<connectionStrings> 
<!-- Server A--> 
<!--add name="MyEntities" connectionString="******;user id=********;password=**********;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient"--> 
<!--Server B--> 
<!--add name="MyEntities" connectionString="******;user id=********;password=**********;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient"--> 
<!--Server C--> 
<add name="MyEntities" connectionString="******;user id=********;password=**********;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient"/> 
</connectionstrings> 

如果我註釋掉服務器C,並取消服務器A和建設項目,會出現此錯誤:

BindingRedirect缺少必需的字段「NEWVERSION」

當我雙擊並檢查錯誤的位置,這使我這行代碼:

<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" nembnwVersion="5.5.0.0" /> 

正如你所看到的, 「NEWVERSION」 莫名其妙地被修改爲 「nembnwVersion = 」5.5.0.0「」 ...

然後我必須糾正錯誤,並再次重建。一旦重建,我會收到一條消息,說我的文件已被編輯,需要重新加載。我重新加載併發生錯誤。每當我更改web.config或嘗試編輯我當前使用的服務器時,都會發生這種情況。我怎樣才能阻止我的web.config自動將「newVersion」更改爲隨機字符串?正如我所提到的那樣,它不是一個破壞項目的錯誤,但它確實非常煩人,浪費了我的時間。

回答

0

我遇到了綁定重定向,因爲assemblyBinding元素上缺少名稱空間而無法工作。

正確的代碼:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="CMS.CompanyValues" publicKeyToken="1a696d1f90f6158a"/> 
    <bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/> 
    </dependentAssembly> 

錯誤代碼:

注丟失:xmlns="urn:schemas-microsoft-com:asm.v1"

<assemblyBinding> 
    <dependentAssembly> 
    <assemblyIdentity name="CMS.CompanyValues" publicKeyToken="1a696d1f90f6158a"/> 
    <bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/> 
    </dependentAssembly> 

希望它會幫助你。

+0

我檢查並且遺憾地在我的程序集綁定中已經有了「xmlns =」urn:schemas-microsoft-com:asm.v1「,謝謝你的幫助 –

+0

我認爲你正在使用'nembnwVersion'而不是'newVersion '。 –

+0

在我的文章中,你會看到'''我使用'newVersion'而不是'nembnwVersion' –