在ASP> NET中为不同用户登录进行身份验证 [英] Aunthentication with login for different users in ASP>NET

查看:62
本文介绍了在ASP> NET中为不同用户登录进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我一直在做的登录。登录有效,但我想改变一些事情。我想在程序的用户之间进行身份验证。每个用户都有用户名和密码。他们也有身份证。我想使用ID进行身份验证,以便为该用户显示一个页面。现在它适用于关卡。我给每个测试用户一个不同的级别。我如何使用ID为他们提供相同的访问权限,但只为他们显示一个页面?那个页面怎么只显示他们的个人资料而没有其他人呢?这是我的代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Data;


public partial class 登录:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

}

< span class =code-keyword> protected void Button1_Click( object sender,EventArgs e )
{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ PasswordConnectionString]。ConnectionString);
con.Open();

if true
{
SqlCommand level = new SqlCommand( 从TableSecurity中选择AccessLevel,密码其中EmailAddress = @EmailAddress AND Password = @Password,con);
level.Parameters.Add( new SqlParameter( EmailAddress,TextBoxEA.Text));
level.Parameters.Add( new SqlParameter( 密码,TextBoxPW.Text));

SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(读者);

foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1 [ 0 ]。ToString());

if (returnedLevel == 1
{
Response.Redirect( FormAPublic.aspx);
}
else if (returnedLevel == 2
{
Response.Redirect( FormCPrivateNon.aspx );
}
else if (returnedLevel == 3
{
Response.Redirect( FormDPrivateFor.aspx );
}
else if (returnedLevel == 7
{
Response.Redirect( CEOPage.aspx );
}
else if (returnedLevel == 8
{
Response.Redirect( DBPage.aspx );
}
}
}
con.Close();
}

}

解决方案

您需要从用户的动态创建该个人资料页面个人资料表。那就是您拥有页面布局以及要显示哪些配置文件信息的位置。因此,当用户登录时,转到用户配置文件表,获取详细信息并将其放在已经提供的位置。



我希望这会有所帮助。

I have a login that I have been working on. The login works but I want to change somethings. I want to authenticate between users of the program. Every user has a username and password. They also have an ID. I want to authenticate with the ID to show a page just for that user. Right now it works with the levels. I gave each test user a different level. How can I use the ID to give them the same access but show them a page just for them? And how can that page only show their profile and no one else? 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["PasswordConnectionString"].ConnectionString);
        con.Open();

        if (true)
        {
            SqlCommand level = new SqlCommand("select AccessLevel, Password from TableSecurity where EmailAddress = @EmailAddress AND Password = @Password", con);
            level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.Text));
            level.Parameters.Add(new SqlParameter("Password", TextBoxPW.Text));

            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("FormAPublic.aspx");
                }
                else if (returnedLevel == 2)
                {
                    Response.Redirect("FormCPrivateNon.aspx");
                }
                else if (returnedLevel == 3)
                {
                    Response.Redirect("FormDPrivateFor.aspx");
                }
                else if (returnedLevel == 7)
                {
                    Response.Redirect("CEOPage.aspx");
                }
                else if (returnedLevel == 8)
                {
                    Response.Redirect("DBPage.aspx");
                }
            }
        }
        con.Close();
    }
    
}

解决方案

You will need to dynamically create that profile page from the user's profile table. That is you have the layout of the page and where you want to display what profile information. So when user logs in, go to the User Profile table, get the details and put them in the places already provided for.

I hope this helps.


这篇关于在ASP&gt; NET中为不同用户登录进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆