2008-11-21 145 views
30

我有一個在我們的本地環境中工作正常的ASP.NET 2.0應用程序。發佈到測試服務器時,我們在服務器上收到間歇性錯誤。「Padding is Invalid and can not be removed」Exception on WebResource.axd

以下是最常見的:

填充無效且無法刪除。 描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

Exception Details: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[CryptographicException: Padding is invalid and cannot be removed.]
System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +1545747
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +257
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +30 System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo) +164
System.Web.UI.Page.DecryptString(String s) +83
System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +148
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

這發生在對特定WebResource.axd請求的請求上。

,我們所看到的其他錯誤是這樣的:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

此錯誤時有發生,同時發佈的形式。

現在你在跳,並告訴我明顯的(通常)回答這個錯誤之前,考慮一下:

  • 將應用程序部署到Windows Server 2003上IIS6
  • 它不是一個網絡上農場。這裏只有一個網絡服務器正在使用。
  • 應用程序池標識是一個自定義服務帳戶,我在服務器上運行aspnet_regiss -ga <username>。沒有效果。
+1

已爲此添加了明確的答案,請查看:) – eglasius 2009-03-06 07:50:25

+0

任何類型的解決方案,但本?我在25分鐘內就您報告的第一個錯誤提供了15封Exceptioneer報告。在安裝fx3.5 sp1後,Rackspace被認爲*昨晚重新啓動,我認爲這些都是由此引起的。但是,我發現他們「忘記」根據我們的票證重新啓動它。以下是有關錯誤報告的鏈接 - http://exceptioneer.com/Share/Summary.aspx?e5dca865-cb2c-4292-af3f-e9d645a081a7。 – 2009-12-02 16:26:39

+1

我從來沒有解決過這個問題。它從來沒有在我們的優先列表的頂部。現在我在一個不同的項目上,所以......我知道的幫助並不多。 – 2009-12-03 06:15:38

回答

24

錯誤是因爲您的appdomain被回收/重新啓動。當發生這種情況時,應用程序和機器鍵被設置爲自動,它會改變。這會影響資源url(.axd)的url中信息的解密。設置一個固定的機器鑰匙將防止它再次發生。

請在類似情況下獲得更多信息檢查這個(對此的解釋是與視圖狀態驗證的問題,但原因是同一個):http://www.developmentnow.com/blog/InvalidViewstate+Or+Unable+To+Validate+Data+Error.aspx

我也一直想知道它相當長的一段。在我看到這個問題後,我再次看到它:Is this an attempt to break my ASP.Net site's security? ......我剛剛回答的內容非常相似。我感覺這是圍繞某種東西重新開始的,因爲當我們發佈了一些可以回收應用程序的東西時,錯誤在日誌中顯示,但是我沒有任何其他來源說明它的關係(今天我在invalidviewstate上發現了這種情況,因爲機器鑰匙改變:))

Ps。以上終於在單臺服務器上解釋它:)

1

在頁面完全加載到瀏覽器中之前生成帖子時,會出現此問題。看看this的問題。

+0

這就是我正在考慮的第二個問題,但它發生的次數多於舒適。 這並不能解釋第一個錯誤,這在我們的例子中要嚴重得多。 – 2008-11-21 19:40:52

0

奔,

對於你的第一個問題,我發現這似乎是多一點,你所看到的,該問題是偶發性的點。 你應該能夠在http://www.codeproject.com/KB/security/Cryptor.aspx#aes找到完整的解釋。

你真正需要做的是將RijndaelAlg.Padding設置爲PaddingMode.ISO10126,PaddingMode.PKCS7或PaddingMode.ANSIX923。只要您在加密和解密時使用相同的值,這三個值中的任何一個值都可以工作。其他值可用於某些數據,但不適用於所有數據。上面的URL解釋了原因。

我不明白的是,微軟提供的選項有時不起作用,或者至少爲什麼他們不默認可靠的選項。

相關問題