繁体   English   中英

ASP.NET C#登录系统

[英]asp.net c# login system

我正在使用登录系统开发系统,其中有三种类型的安全性级别用户,管理员,管理员,并且系统用户将超过1500个用户,所以我对asp.net有点陌生,因此我想尽全力覆盖asp中的会员系统.net原因我发现它是如此复杂,我的用户表结构是

user_id int
user_pass int
user_level int    there will be one of three values in this column 1 or 2 or 3

而我的网络配置身份验证部分是

<authentication mode="Forms">

    <forms loginUrl="login.aspx" name="3345C" timeout="60" protection="All" >
        <credentials passwordFormat="Clear">
            <user name="nissadmin" password="nissADM"/>
            <user name="nissuser" password="nissuser"/>
        </credentials>
    </forms>
</authentication>
<location path="oper">
    <system.web>
        <authorization>
            <allow users="nissuser"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
<location path="admin">
    <system.web>
        <authorization>
            <allow users="nissadmin"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>      

我的登录页面代码是

protected void Button1_Click(object sender, EventArgs e)
    {
        string connectionString
        = System.Configuration.ConfigurationManager.ConnectionStrings["nisss"].ConnectionString;
        SqlConnection conn = new SqlConnection();
        try
        {
            if (user.Text == "" || pw.Text == "")
            {
                Label1.Text = "Please Fill the required Fields";
            }
            else
            {
                conn = new SqlConnection(connectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand("logi", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@usr", int.Parse(user.Text)));
                cmd.Parameters.Add(new SqlParameter("@pass", pw.Text));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet data = new DataSet();
                da.Fill(data);
                if (data.Tables[0].Rows.Count == 1) // if the user and password true
                {
                    int role = data.Tables[0].Rows[0].Field<int>(3);
                    Response.Cookies["id"].Value = user.Text;
                    if (role == 0)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissuser", "nissuser"))
                        {
                            system.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissuser", false);
                            Response.Cookies["rolee"].Value = null;
                            Response.Redirect("oper/order.aspx");
                        }

                    }
                    else if (role == 1)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissuser", "nissuser"))
                        {
                            System.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissuser", false);
                            Response.Cookies["rolee"].Value = "456";
                            Response.Redirect("oper/order.aspx");
                        }
                    }
                    else if (role == 2)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissadmin", "nissADM"))
                        {
                            System.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissadmin", false);
                            Response.Redirect("admin/tabs.html");
                        }
                    }
                }
                else
                {
                    Label1.Text = "wrong password or id";
                }
            }
        }
        finally
        {
            conn.Close();
        }
    }

这在测试中效果很好,但是我所需要知道的是,它将可以与大量用户同时登录而不会出现任何问题,请提前帮助我谢谢

首先,我将使用内置的成员资格提供程序来添加一个asp.net表单身份验证的示例。 工作完成后,我将考虑对成员资格提供程序进行子分类以自定义安全模型。

您上面所拥有的东西太复杂了,您在一处承担太多责任。

您可能还想看看SimpleMembership Provider

尝试使用int.TryParse而不是int.Parse。 您永远不知道哪些用户可以在该字段中输入...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM