Padding is invalid and cannot be removed 解决方法
2009-11-09 13:44
609 查看
最近,客户浏览公司开发的网站时,老是出现 Padding is invalid and cannot be removed 的错误
具体信息如下:
Server Error in '/gzdisable' Application.
--------------------------------------------------------------------------------
Padding is invalid and cannot be removed.
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.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) +7594654
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +208
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +225
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +246
ZSoft.Web.Engine.GetCookie(HttpContext context, String cookieName) +140
ZSoft.Web.Engine.SetContext(String cookieName) +130
ZSoft.Web.Engine.SetContext() +55
ZSoft.Web.HttpModule.BeginRequest(Object sender, EventArgs e) +45
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
经查询,发现是因为网站用了负载平衡(Web Farm) 而且启用视图状态加密而导致的。
解决方法有两种:
1,可以同时在各台负载平衡的网站web.config的<system.web>节点加上这个节点
<machineKey validationKey="0BE61B38B9836B541C45728ADB9D93A6FD819169DBB6AD20078A70F474650CC0295C69131E083A6B3762C457BBAF3E66E18F294FDA434B9DD6758631A90A2E20" decryptionKey="B80CC12266B36CCF35EF0708DB5854EDA3BBEBA1A7C89A4E" validation="SHA1"/>
这样可以保持对试图状态的加密,又不会出现错误
2, 可在web.config 作如下配置,目的是关闭视图状态加密
<system.web>
<pages enableViewStateMac="false" />
</system.web>
也可在每个页面前面单独配置:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MyPage.aspx.vb"
Inherits="MyAssembly.MyPage" enableViewStateMac="False" %>
在此引用MSDN对EnableViewStateMac的解释:
EnableViewStateMac 指示当页从客户端回发时,ASP.NET 是否应该对页的视图状态运行计算机身份验证检查 (MAC)。如果应该对视图状态运行 MAC 检查,则为 true;否则为 false。默认值为 true。
其实对于一般的网站,没有必要对ViewState加密,建议用第二种解决方案。
参考:
1,Web Farm And Web Garden
2,Padding is invalid and cannot be removed
具体信息如下:
Server Error in '/gzdisable' Application.
--------------------------------------------------------------------------------
Padding is invalid and cannot be removed.
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.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) +7594654
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +208
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +225
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +246
ZSoft.Web.Engine.GetCookie(HttpContext context, String cookieName) +140
ZSoft.Web.Engine.SetContext(String cookieName) +130
ZSoft.Web.Engine.SetContext() +55
ZSoft.Web.HttpModule.BeginRequest(Object sender, EventArgs e) +45
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
经查询,发现是因为网站用了负载平衡(Web Farm) 而且启用视图状态加密而导致的。
解决方法有两种:
1,可以同时在各台负载平衡的网站web.config的<system.web>节点加上这个节点
<machineKey validationKey="0BE61B38B9836B541C45728ADB9D93A6FD819169DBB6AD20078A70F474650CC0295C69131E083A6B3762C457BBAF3E66E18F294FDA434B9DD6758631A90A2E20" decryptionKey="B80CC12266B36CCF35EF0708DB5854EDA3BBEBA1A7C89A4E" validation="SHA1"/>
这样可以保持对试图状态的加密,又不会出现错误
2, 可在web.config 作如下配置,目的是关闭视图状态加密
<system.web>
<pages enableViewStateMac="false" />
</system.web>
也可在每个页面前面单独配置:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MyPage.aspx.vb"
Inherits="MyAssembly.MyPage" enableViewStateMac="False" %>
在此引用MSDN对EnableViewStateMac的解释:
EnableViewStateMac 指示当页从客户端回发时,ASP.NET 是否应该对页的视图状态运行计算机身份验证检查 (MAC)。如果应该对视图状态运行 MAC 检查,则为 true;否则为 false。默认值为 true。
注意: |
---|
视图状态 MAC 是隐藏变量的加密版本,当某页被发送到浏览器时,该页的视图状态永久保持到该变量中。当您将此属性设置为 true 时,将检查加密的视图状态以验证它在客户端未被篡改。注意,将此属性设置为 true 会影响性能,因为在页的每次往返行程中,都必须加密和解密变量值。 |
参考:
1,Web Farm And Web Garden
2,Padding is invalid and cannot be removed
相关文章推荐
- U8v10.1 启动系统管理出现padding is invalid and can't be removed问题的解决方法
- Padding is invalid and cannot be removed. 一直提示这个 怎么解决?
- 二级域名共享Cookie时碰到的问题:Padding is invalid and cannot be removed
- Padding is invalid and cannot be removed
- 异常CryptographicException: "Padding is invalid and cannot be removed."的原因
- 填充无效,无法被移除(Padding is invalid and cannot be removed)
- 填充无效,无法被移除(Padding is invalid and cannot be removed)
- Padding is invalid and cannot be removed
- 项目名 is required and cannot be removed from the server解决
- RAC root.sh Oracle CRS stack is already configured and will be running under init(1M) 的解决方法
- 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
- Table ‘xxx’ is marked as crashed and should be repaired 错误解决方法参考
- RAC root.sh Oracle CRS stack is already configured and will be running under init(1M) 的解决方法
- 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
- iOS中项目运行到真机上提示设备被锁定解决方法Development cannot be enabled while your device is locked.
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- iOS中项目运行到真机上提示设备被锁定解决方法Development cannot be enabled while your device is locked.
- php 报: 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the f
- Webdriver Element is not currently visible and so may not be interactedwith 解决方法
- Table ‘xxx’ is marked as crashed and should be repaired 错误解决方法