c#windows应用程序中的用户角色管理 [英] user roles management in c# windows application

查看:71
本文介绍了c#windows应用程序中的用户角色管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,使用c#在Windows窗体应用程序上工作,几个用户可以使用不同的角色,例如3个角色,即角色只访问程序的某些部分,无法查看和访问它,B角色可以访问整个应用程序,但有些部分只是正确访问和查看,C角色完全访问应用程序i的所有部分在数据库(sql server)中拥有这些角色和用户。



有什么好办法来制作这个应用程序吗?



提前感谢...

hi all,

i wana work on a windows forms application using c# that several users can work with different roles, for example 3 roles ,that "A role" only to access some parts of the program and cannot see and access it and "B role" can acess to entire of application, but some parts are just right to access and view, "C role" full access to all parts of the Application i have these roles and users in a database (sql server).

whats a good way for make this application?

thanks in advance...

推荐答案





一个解决方案可能是:

最初有一个登录页面,您可以通过他的ID和密码对用户进行身份验证,并检查他是否有角色A,B或C.

角色C在您的情况下将是Admin。

当用户被认证为A或B或C时,将它们重定向到具有所需功能的单独win表单。

Ex:Ro le A可以更改他的密码,查看他已注册的课程,而作为管理员的角色C可以查看所有角色,编辑角色,编辑课程,查看/编辑其他用户支付的费用和内容。 />


这里的关键是有一个共同的登录页面,根据他的id和密码对用户进行身份验证,并检查你的DB是否有什么角色,然后将它们重定向到他们的个人形式。



希望有所帮助。



问候

Anurag
Hi,

One solution might be:
Have a login page initially where you authenticate the user by his id and password and check whether he has role A,B or C.
Role C in your case will be the Admin.
As the user is authenticated as A or B or C, redirect them to separate win forms having desired functionalities as you need.
Ex: Role A can change his password, view the courses he has enrolled with, while role C being an admin can view all the roles, edit the roles, edit the courses, view/edit the fees paid by the other users and stuffs.

The key here is to have a common login page, authenticate a user based upon his id and password and check in ur DB whether what role he has, and then redirect them to their individual forms.

Hope it helps.

Regards
Anurag


虽然RoleProvider和Membership provider功能与asp.net一起使用,但您也可以将它与WindowsForms应用程序一起使用,请参阅此文章: http://mkdot.net/community/mknetug/mk_sp/b/zzl/archive/2008/04/09/using-the-built-in-asp-net-role-provider-in-windows-forms-或控制台-applications.aspx [ ^ ]。其余的将与asp.net的情况大致相同,并且由于有内置的即用型SqlRoleProvider,因此可以直接使用它: http://msdn.microsoft.com/en-us/library/ff647401.aspx [ ^ ]
Although RoleProvider and Membership provider functionality is meant to be used with asp.net, you can use it with WindowsForms applications too, see this article: http://mkdot.net/community/mknetug/mk_sp/b/zzl/archive/2008/04/09/using-the-built-in-asp-net-role-provider-in-windows-forms-or-console-applications.aspx[^]. The rest will be much the same as in case of asp.net, and as there is a built-in ready to use SqlRoleProvider, it is straightforward to use it: http://msdn.microsoft.com/en-us/library/ff647401.aspx[^]


我们可以为您提供准备好的代码安静对你来说,我更喜欢你,如果你深入了解我们所说的:会员管理,特别是如果你想以正确的方式做到这一点,我个人之前遇到过这个问题而且我看起来像是为了准备好代码但是我在阅读文章和文档后意识到有很多东西需要了解。

首先,你可以使用很多解决方案,其中一个是Asp.Net Membership,但还有其他的所以你需要了解它们并找到对你有帮助的东西,但我会谈论ASP.Net Membership !

所以你需要了解的是:使用专业制造的技术!而不是重新发明轮子,避免创建自己的管理系统。

Asp.Net会员资格为您提供所需的...

这里是我开始的链接: YOUTUBE上的视频 [ ^ ]



您需要了解的是,这可能是一个Web应用程序示例!但它是一个简单的数据库......就像任何其他数据库和一些代码一样!所以你可以在winform应用程序中使用它!(只需配置你的App.Config文件,这样它就会指向正确的数据库:试试了解什么:提供商意味着他们的工作是什么)

这是一个代码示例,您可以使用它来检查例如,如果这是一个用途:



we can give you a "ready" peace of code to you, i prefer if you dig in that to understand more about what we call : Membership management, specially if you want to do it the right way, personally i had that problem before and i was looking like you for a ready peace of code, but i realized after reading articles and documentation that there is a lot to understand about that.
So first there are many solutions you can use, one of them is Asp.Net Membership, but there are others so you need to know them and find what helps you the most, but i will talk about ASP.Net Membership little !
So what you need to understand, is to : "use technology made by professional ! instead of reinventing the wheel", avoid creating your own managing system.
Asp.Net Membership provide you what you need...
here is a link where i started : VIDEO ON YOUTUBE[^]

what you need to understand is that, this may be a Web Application example ! but it's a simple Database...just like any other Database and some code ! so you can use it in a winform application ! (just configure your App.Config file so it will point to the right Database : try to understand what : Providers means what is their job)
this is an example of code you can use to check for example if a this is a use :

//Check if the tbLogin and tbPassword are for a Member or not :
if (Membership.ValidateUser(tbLogin.Text, tbPassword.Text))
{
    MessageBox.Show("Connected");
}
// treatment if authenticated

else
{
    MessageBox.Show("Not Connected");
}
this.Dispose();




$ b从用户名中获取MembershipUser对象的$ b或代码的和平:





or this peace of code to get MembershipUser object from the User Name :

private MembershipUser GetUserMembershipFromUserName(string userName)
        {
            var mu = Membership.GetUser(userName);
            return (mu);
        }





从这个MemebershipUser对象中你可以获得任何你想要的东西:ID,电子邮件,角色......等等!

你可以在每次加载winform时使用这段代码来保持/重定向用户!

无论如何在这个主题中有很多话要说这就是为什么我希望你准备更多关于它的事情,抱歉,如果我的英语不是很好,如果你需要更多的帮助,请告诉我,祝你好运:))



and from that MemebershipUser Object you can get anythg you want : ID, Email, Role...etc!
you can use this peace of code in each loading of winform to keep/redirect the user !
anyway there is so much to talk about in this topic this is why i wanted you to ready more about it, sorry if my English is not very good, if you need more help let me know, good luck :)


这篇关于c#windows应用程序中的用户角色管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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