1

ログインシステムを使用してシステムをデボルピングしています。セキュリティレベルにはユーザー、マネージャー、管理者の3つのタイプがあり、システムユーザーは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

そして私のWeb構成認証部分は

<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();
        }
    }

これはテストでは問題なく動作しますが、私が知る必要があるのは、これが膨大な数のユーザーが同時にログインしても問題なく動作するということだけです。よろしくお願いします。

4

2 に答える 2

0

int.Parseの代わりにint.TryParseを使用してみてください。ユーザーがフィールドに何を入力できるかはわかりません...

于 2012-10-30T10:51:42.437 に答える
0

最初に、組み込みのメンバーシップ プロバイダーを使用した asp.net フォーム認証の例をスパイクします。それが機能したら、メンバーシップ プロバイダーをサブクラス化してセキュリティ モデルをカスタマイズする方法を検討します。

あなたが上に持っているものはあまりにも複雑で、1 つの場所にあまりにも多くの責任があります。

SimpleMembership Providerもご覧ください。

于 2012-10-30T10:48:48.340 に答える