如何在查询中添加管理员和用户 [英] how to add admin and user in a query

查看:89
本文介绍了如何在查询中添加管理员和用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码创建一个登录页面。

这只适用于用户,但现在我想要管理员帐户,所以我必须在此代码中进行哪些更改:



I am making a login page using this code.
This is only for user but now i want to admin account also so what changes i have to make in this code:

try
            {
                SqlConnection con = new SqlConnection(@"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False");
                string query = "SELECT [user].* FROM [user] where u_name='" + txtusername.Text + "' and pwd='" + txtpassword.Text + "'";
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                if (com.ExecuteReader().HasRows)
                {
                    //if ((txtusername.Text = "admin") && (txtpassword.Text = "admin"))
                    {
                        Response.Redirect("allinventory.aspx");
                        Label3.Text = "successfully";


                    }
                }
                else
                {
                    Label3.Text = "not successfully";
                    txtusername.Text = "";
                    txtpassword.Text = "";
                }
                con.Close();
            }
            catch (Exception ex)
            {
                Console.Write("" + ex.Message);
            }

推荐答案

您好,



您可以使用数据库中的角色,以便您可以根据角色重定向用户,如果角色是管理员,那么他可以访问管理员部分,或者如果他是用户,那么他可以作为用户访问他的帐户。你只需要三个数据库表: -



1.用户

2.角色

3. UsersInRoles



用户表将保存用户详细信息。



角色表将保留您的站点角色。(例如Admin,用户)



UsersInRoles将保存用户和角色表的映射。



您可以创建存储过程到根据给定的凭据获取用户详细信息和角色。



谢谢
Hi,

You can use roles in your database so that you can redirect users according to their roles if the role is ''Admin'' then he can access admin section or if he is user then he can access his account as user. You just need three database tables:-

1. Users
2. Roles
3. UsersInRoles

Users table will hold user details.

Roles table will hold your site roles.(e.g. Admin, User)

UsersInRoles will hold mapping of Users and Roles table.

You can create stored procedure to get user details and roles according to given credentials.

Thanks


这篇关于如何在查询中添加管理员和用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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