我正在尝试使用角色进行简单登录。 [英] I'm trying to do a simple login with roles.

查看:49
本文介绍了我正在尝试使用角色进行简单登录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



有没有人知道教程或想要发布如何使用角色登录。当用户登录时,我想将它们重定向到特定页面。通过:管理页面或合作伙伴页面,客户页面。如果没有登录,也必须无法进入其中任何一个页面。我发现了很多代码,我可以在不必登录的情况下进入管理页面。我也尝试了ASP.NET配置,但它似乎过度杀戮。另外,我似乎无法让它去做我正在寻找的东西。



任何帮助将不胜感激。谢谢



我尝试了什么:



我发现了很多代码我可以在不必登录的情况下进入管理页面。我也尝试过ASP.NET配置,但它似乎过度杀戮。另外我似乎无法让它去做我正在寻找的东西。

Hello,

Does anyone know of a tutorial or would like to post how to do a login with roles. When the user login I would like to redirect them to a particular page. Via: Admin page or Partners page, Customer Page. Also must not be able to enter either of those pages without signing in. I found plenty of code that I can get to a Admin page without having to sign in. I also tried the ASP.NET Configuration but it seemed like over kill. Plus I can't seem to get it to do what I'm looking for.

Any help would be greatly appreciated. Thanks

What I have tried:

I found plenty of code that I can get to a Admin page without having to sign in. I also tried the ASP.NET Configuration but it seemed like over kill. Plus I can't seem to get it to do what I'm looking for.

推荐答案

你在使用MVC吗?如果是这样,什么版本?



如果没有,你必须使用Session,以下是如何使其工作的逻辑。



在DB中设置用户类型,然后在用户登录时,获取用户类型并根据用户类型创建会话。



像这样:

if(userType == 1){Session [Admin] = objUserAdmin;等等



然后在Admin区域的Index.aspx的Page_Load上,检查Session [Admin]!= null ...如果是null,只是重定向用户,因为他不是管理员。



您必须调整代码以适应您的所有用户类型



希望它有所帮助!
Are you using MVC? If so, what version?

If not, you must use Session and below is the logic on how to make it work.

Set the user type in DB, then when the user logs in, get the user type and create the Session based on user type.

Like this:
if (userType == 1) { Session["Admin"] = objUserAdmin; } and so on

Then on Page_Load from your Index.aspx on Admin area, just check if the Session["Admin"] != null... if it's null, just redirect the user, because he isn't admin.

You must adapt your code to work with all of your user type

Hope it helps!


让我们把它作为你在数据库中的角色A(admin)U(用户)

使用以下代码检查角色并重定向到所需页面



Lets take it as you have a role on your database as A(admin) U(user)
Use below code to check the role and redirect to their desired page

string Utype;
           Utype = dt.Rows[0][10].ToString().Trim();// This will count and select the role A or U from your table.so remember to change the rows number according to your table data
           if (Utype == "U")
           {
               Session["Username"] = UserName.Text;
               Response.Redirect("UserHome.aspx");
           }
           else if (Utype == "A")
               Session["Username"] = UserName.Text;
           Response.Redirect("~/Admin/Admin_Home.aspx");

       }


       else
       {
           lblError.ForeColor = Color.Red;
           lblError.Text = "Invalid Username or Password";
       }
       }


在这个主题上有几本使用ASP.NET的好书。得到其中一个。它不需要是最新版本,所以你可以很少得到一本旧书。
There are several good books using ASP.NET on the subject. Get one of those. It doesn't need to be the latest version, so you can get a used book for very little.


这篇关于我正在尝试使用角色进行简单登录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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