簡體   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