Bootstrap

验证视图状态 MAC 失败,配置machineKey

在webconfig中system.web节点下添加:

<system.web>

    <machineKey validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES" validation="SHA1"/>

</system.web>

    

machineKey生成的算法:


<script language="c#" runat="server">

    #region Page_Load

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            var validationKey = CreateKey(20);

            var decryptionKey = CreateKey(24);

            Response.Write("validationKey:"+validationKey);
            Response.Write("<br>");
            Response.Write("decryptionKey:"+decryptionKey);
        }
    }

    #endregion


     protected string CreateKey(int len)
     {

            byte[] bytes = new byte[len];

            new System.Security.Cryptography.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();

     }
    

</script>
    
————————————————

 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/manimanihome/article/details/95473562

;