2013-10-16 71 views
6

我有一個簡單的.net應用程序,它使用IIS 7.5中的.NET 2.0運行時,我已更改web.config中的計算機密鑰以使用以下內容:無法驗證數據錯誤,並將機器密鑰設置爲SHA1

<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="SHA1"/> 

這適用於本地,但是當我發佈到服務器時,我收到一個「HttpException(0x80004005):無法驗證數據」每當瀏覽網站。我已經確保設置編譯debug =「false」。將驗證方法設置爲3DES可消除此問題,但我們需要使用SHA1。有沒有我在這裏失蹤的配置選項?請參閱下面的堆棧跟蹤。

 
[HttpException (0x80004005): Unable to validate data.] 
    System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo, Boolean signData) +1008 
    System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +91 
    System.Web.UI.Page.EncryptStringWithIV(String s, IVType ivType) +83 
    System.Web.UI.Page.EncryptString(String s) +30 
    System.Web.Handlers.RuntimeScriptResourceHandler.GetScriptResourceUrlImpl(List`1 assemblyResourceLists, Boolean zip, Boolean notifyScriptLoaded) +1497 
    System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(List`1 assemblyResourceLists, Boolean zip, Boolean notifyScriptLoaded) +1148 
    System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +152 
    System.Web.Handlers.ScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +37 
    System.Web.UI.ScriptManager.GetScriptResourceUrl(String resourceName, Assembly assembly) +105 
    System.Web.UI.ScriptRegistrationManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +113 
    System.Web.UI.ScriptManager.System.Web.UI.IScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +14 
    System.Web.UI.ClientScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +53 
    System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e, Boolean registerScript) +113 
    System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +25 
    System.Web.UI.Control.PreRenderRecursiveInternal() +80 
    System.Web.UI.Control.PreRenderRecursiveInternal() +171 
    System.Web.UI.Control.PreRenderRecursiveInternal() +171 
    System.Web.UI.Control.PreRenderRecursiveInternal() +171 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 

回答

2

我發現當「系統密碼學:使用fips兼容算法進行加密,散列和簽名」(安全設置>>本地策略>> securityOptions)的本地安全策略設置爲true時,Sha1將不起作用,這就是我在這種情況下遇到錯誤的原因。

+0

我可以看到這個選項? - 安全設置>>本地策略>> securityOptions – codetoshare

+0

我知道這是舊的,但我認爲我會在筆記中...此設置可在本地計算機策略>計算機配置> Windows設置>安全設置>本地下的組策略編輯器(gpedit.msc)中找到政策>安全選項。您必須更改iisreset後,謝謝! –

4

您是在真正的.NET 2.0應用程序池中運行應用程序嗎? (我問,因爲你使用IIS 7.5)。

如果不是,請記住.NET 4.5框架中的加密算法已經發生變化。

如果你需要與< .NET 4.5框架兼容,你需要一個兼容標籤:

<machineKey compatibilityMode="Framework20SP1" /> 

詳見http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspxhttp://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographic-improvements-in-asp-net-4-5-pt-2.aspx

+0

是的,我的網站的應用程序池設置爲使用.NET 2.0 – Ben

+0

您仍然可以嘗試兼容性標記,如果它不起作用,恐怕我在這裏空白。對不起......:| – Stefan

+0

好吧我試着把建議中的machinekey部分的compatibilityMode標籤,但仍然收到相同的錯誤:( – Ben

相關問題