我正在开发带有登录系统的系统,有三种类型的安全级别用户,经理,管理员,系统用户将超过 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();
}
}
这在测试中运行良好,但我需要知道的是,这将适用于同时登录的大量用户,没有任何问题请帮助我提前感谢