新聞中心
ASP.NET machineKey的作用

如果你的Asp.Net程序執(zhí)行時(shí)碰到這種錯(cuò)誤:“驗(yàn)證視圖狀態(tài) MAC 失敗。如果此應(yīng)用程序由網(wǎng)絡(luò)場(chǎng)或群集承載,請(qǐng)確保
ASP.NET machineKey生成的算法:
- validationKey = CreateKey(20);
- decryptionKey = CreateKey(24);
- protected string CreateKey(int len)
- {
- byte[] bytes = new byte[len];
- new RNGCryptoServiceProvider().GetBytes(bytes);
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < bytes.Length; i++)
- {
- sb.Append(string.Format("{0:X2}",bytes[i]));
- }
- return sb.ToString();
- }
附參考的ASP.NET machineKey配置:
- version="1.0"?>
validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES" validation="SHA1"/>
【編輯推薦】
- .NET框架解決DLL Hell問題:問題描述
- ASP.NET MVC單元測(cè)試:HttpContext類的Path屬性解惑
- 自定義的ControllerFactory:接口實(shí)現(xiàn),支持Area
- ASP.NET Routing之“解析URL”功能詳解
- 為ASP.NET MVC應(yīng)用添加自定義路由
當(dāng)前名稱:ASP.NET machineKey的作用和使用方法
網(wǎng)頁鏈接:http://fisionsoft.com.cn/article/dpdshoe.html


咨詢
建站咨詢
