登录不同级别 [英] Login on Different Levels
本文介绍了登录不同级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我试图找出如何编写代码来完成我的水平。发生的事情是,在登录页面上,我必须编程以从表中获取用户名和密码,以便用户登录。那部分有效。现在我想根据用户级别登录。如果用户是Level1,则页面将重定向到该用户的欢迎页面。如果用户是Level2,则用户转到该页面。这是我的代码:
Hello. I am trying to find out how to write the code to finish my levels. What is going on is that on the Login page I have to program to get the username and password from a table in order to have the user to login. That part works. Now I want to login depending on the user levels. If the user is a Level1 then the page redirects to a Welcome page for that user. If the user is a Level2 then the user goes to that page. Here is the code I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
string cmdStr = "select count(*) from TableSecurity where EmailAddress= '" + TextBoxEA.Text + "'";
SqlCommand Checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
string cmdStr3 = "select Level from TableSecurity where EmailAddress= '" + TextBoxEA.Text + "'";
SqlCommand level = new SqlCommand(cmdStr3, con);
SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(reader);
foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1[0].ToString());
if (returnedLevel == 1)
{
Response.Redirect("~/Secure.aspx");
}
else if (returnedLevel == 2)
{
Response.Redirect("~/WelcomeIALO.aspx");
}
}
}
con.Close();
}
}
推荐答案
也许您首先需要使用本教程学习该主题:http://www.asp.net/web-forms/tutorials/security/roles/基于角色的授权-cs [ ^ ]。
-SA
Perhaps you first need to study the subject using this tutorial: http://www.asp.net/web-forms/tutorials/security/roles/role-based-authorization-cs[^].
—SA
以下是您需要添加/更改以使其正常工作的代码:
Here is the code you need to add/alter in order for it to work:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
string cmdStr = "select count(*) from TableSecurity where EmailAddress= ''" + TextBoxEA.Text + "''";
SqlCommand Checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
con.Close();
string cmdStr3 = "select Level from TableSecurity where EmailAddress= ''" + TextBoxEA.Text + "''";
con.Open();
SqlCommand level = new SqlCommand(cmdStr3, con);
SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(reader);
foreach(DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1[0].ToString());
if(returnedLevel == 1)
{
Response.Redirect("~/Secure.aspx");
}
else if(returnedLevel == 2)
{
Response.Redirect("~/WelcomeIALO.aspx");
}
}
}
con.Close();
}
这篇关于登录不同级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文