想在我的登录页面上定义角色和身份验证 [英] want to define roles and authentication on my login page

查看:81
本文介绍了想在我的登录页面上定义角色和身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个登录页面我想要的东西1我想要定义角色nad第二次使我的代码认证soo没有人可以从url访问。

请帮助我





i have made a login page i want to thing in it 1st i want to define roles nad 2nd make my code authentication soo no one can access from url.
please help me for that


try
            {
                SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator.LENOVO-74FE9906\Desktop\Orignal Project Part 1\Inventory Management System\IMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
                string query = "SELECT [user].* FROM [user] where u_name='" + txtusername.Text + "' and pwd='" + txtpassword.Text + "'";
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                if (txtusername.Text == "admin")
                {

                    if (com.ExecuteReader().HasRows)
                    {


                        Response.Redirect("index.html");
                        Label3.Text = "successfully";



                    }
                    else
                    {
                        Label3.Text = "not successfully";
                        txtusername.Text = "";
                        txtpassword.Text = "";
                    }
                }
                else if (txtusername.Text == "user")
                {
                    if (com.ExecuteReader().HasRows)
                    {


                        Response.Redirect("userinventory.aspx");
                        Label3.Text = "successfully";



                    }
                    else
                    {
                        Label3.Text = "not successfully";
                        txtusername.Text = "";
                        txtpassword.Text = "";
                    }
                }

                con.Close();
            }
            catch (Exception ex)
            {
                Console.Write("" + ex.Message);
            }

推荐答案

参考以下两个链接



使用角色管理网站用户



如何:实现简单表单身份验证



这足以让您实现您描述的功能。
Refer to Below two links

Managing Web Site Users with Roles

How to: Implement Simple Forms Authentication

That will be enough for you to implement the functionality you described.


这些文章可以帮助您 -

表单身份验证和基于角色的授权:更快,更简单和正确的方法 [ ^ ]



使用成员资格和用户登录构建网站 [ ^ ]



了解和实现ASP.NET自定义表单身份验证 [ ^ ]
these articles may help you-
Forms Authentication and Role based Authorization: A Quicker, Simpler, and Correct Approach[^]

Building a Web Site with Membership and User Login[^]

Understanding and Implementing ASP.NET Custom Forms Authentication[^]


这篇关于想在我的登录页面上定义角色和身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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