当前位置:编程学习 > C#/ASP.NET >>

为什么Windows server 2008 R2的系统下asp.net提交表单时会发生如下的错误?

System.Security.CryptographicException,用Windows XP/2003/2008都不会存在这个问题,为什么会跟系统有关系?

在网上查了好几个办法都无效,郁闷!!!

谢谢各位大神们不吝赐教! asp.net --------------------编程问答--------------------
引用 楼主 wonderful_abc 的回复:
System.Security.CryptographicException,用Windows XP/2003/2008都不会存在这个问题,为什么会跟系统有关系?

在网上查了好几个办法都无效,郁闷!!!

谢谢各位大神们不吝赐教!

你先将提交表单的代码贴出来看下 --------------------编程问答-------------------- 下面的代码在Windows server 2008及以下的服务器版操作系统中都没有问题,就是windows server 2008 R2才发生这个错误,说:System.Security.CryptographicException 系统找不到制定的文件。

protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {
        string username = Request["txtName"];
        string userpwd = Request["txtPassword"];
        DateTime UserTime = DateTime.Now;
        using (SqlConnection strcon = new SqlConnection(MonitoringSystemConfiguration.DbConnectionString))
        {
            using (SqlCommand scd = new SqlCommand("select id,enabled,operation as ff from s_user where login_name='" + username + "' and password='" + new RSA(System.Text.Encoding.Unicode.GetString(Convert.FromBase64String(ConfigurationManager.AppSettings["privateKey"]))).Encrypt(userpwd) + "'", strcon))
            {
                strcon.Open();
                SqlDataReader reader = scd.ExecuteReader();
                if (reader.Read())
                {
                    int id = reader.GetInt32(0);
                    bool count = reader.GetBoolean(1);
                    int role = reader.GetInt16(2);
                    reader.Close();
                    if (count)
                    {
                        Session["UserId"] = id;
                        Session["txtName"] = username;
                        Session["txtPassword"] = userpwd;
                        Session["operation"] = role;                        string N_IP;

                        N_IP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (N_IP == null || N_IP == "")
                        {
                            N_IP = Request.ServerVariables["REMOTE_ADDR"];
                        }                        

                        scd.CommandText = "insert into d_loging (UserID,IP,UserTime)values(@N_User,@N_IP,@UserTime)";
                        SqlParameter para = new SqlParameter("@username", SqlDbType.VarChar, 20);
                        para.Value = username;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@N_User", SqlDbType.Int);
                        para.Value = id;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@N_IP", SqlDbType.VarChar, 30);
                        para.Value = N_IP;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@UserTime", SqlDbType.DateTime);
                        para.Value = UserTime;
                        scd.Parameters.Add(para);
                        scd.ExecuteNonQuery();

                        string tt = " qminoa = window.open('index.aspx" + "'"
                      + ",'','toolbar=no,menubar=no,titlebar=yes,location=no,scrollbars=no,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');";
                        Response.Write("<script language=javascript>");
                        Response.Write(tt);
                        Response.Write("qminoa.moveTo(0,0);");
                        Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);");
                        Response.Write("window.opener=null;");
                        Response.Write("window.close();");
                        Response.Write("</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('该用户已经被禁用,请联系管理员!');history.back()</script>");
                        return;
                    }
                }
                else
                {
                    Response.Write("<script>alert('用户名或者密码错误,请重新输入!');history.back()</script>");
                    return;
                }
            }
        } --------------------编程问答-------------------- http://q.cnblogs.com/q/34257/
http://bbs.csdn.net/topics/390058757
看看这两篇,都是关于快钱支付提示这个错误的问题。希望对你有帮助。 --------------------编程问答-------------------- 程序编译为x86试试
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答--------------------
引用 2 楼 wonderful_abc 的回复:
下面的代码在Windows server 2008及以下的服务器版操作系统中都没有问题,就是windows server 2008 R2才发生这个错误,说:System.Security.CryptographicException 系统找不到制定的文件。

protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {
        string username = Request["txtName"];
        string userpwd = Request["txtPassword"];
        DateTime UserTime = DateTime.Now;
        using (SqlConnection strcon = new SqlConnection(MonitoringSystemConfiguration.DbConnectionString))
        {
            using (SqlCommand scd = new SqlCommand("select id,enabled,operation as ff from s_user where login_name='" + username + "' and password='" + new RSA(System.Text.Encoding.Unicode.GetString(Convert.FromBase64String(ConfigurationManager.AppSettings["privateKey"]))).Encrypt(userpwd) + "'", strcon))
            {
                strcon.Open();
                SqlDataReader reader = scd.ExecuteReader();
                if (reader.Read())
                {
                    int id = reader.GetInt32(0);
                    bool count = reader.GetBoolean(1);
                    int role = reader.GetInt16(2);
                    reader.Close();
                    if (count)
                    {
                        Session["UserId"] = id;
                        Session["txtName"] = username;
                        Session["txtPassword"] = userpwd;
                        Session["operation"] = role;                        string N_IP;

                        N_IP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (N_IP == null || N_IP == "")
                        {
                            N_IP = Request.ServerVariables["REMOTE_ADDR"];
                        }                        

                        scd.CommandText = "insert into d_loging (UserID,IP,UserTime)values(@N_User,@N_IP,@UserTime)";
                        SqlParameter para = new SqlParameter("@username", SqlDbType.VarChar, 20);
                        para.Value = username;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@N_User", SqlDbType.Int);
                        para.Value = id;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@N_IP", SqlDbType.VarChar, 30);
                        para.Value = N_IP;
                        scd.Parameters.Add(para);
                        para = new SqlParameter("@UserTime", SqlDbType.DateTime);
                        para.Value = UserTime;
                        scd.Parameters.Add(para);
                        scd.ExecuteNonQuery();

                        string tt = " qminoa = window.open('index.aspx" + "'"
                      + ",'','toolbar=no,menubar=no,titlebar=yes,location=no,scrollbars=no,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');";
                        Response.Write("<script language=javascript>");
                        Response.Write(tt);
                        Response.Write("qminoa.moveTo(0,0);");
                        Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);");
                        Response.Write("window.opener=null;");
                        Response.Write("window.close();");
                        Response.Write("</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('该用户已经被禁用,请联系管理员!');history.back()</script>");
                        return;
                    }
                }
                else
                {
                    Response.Write("<script>alert('用户名或者密码错误,请重新输入!');history.back()</script>");
                    return;
                }
            }
        }

跟踪一下,看到哪个地方报的错
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,