Hi ,
i'm developing a permission-based win application
there is one Permission for each possible Action in db & each Role
has
some Permissions
and a custom authentication system is implemented for identifying
users and their roles
now,
1.i want to know what's advantages of using .Net Role-Based
Security ?
i mean for controlling access of user to resources i could simply use
something like this :
** if (currentuser.Ha sPermission("Re quiredPermissio n")) then do the
action **
2.i would check user permission in Business layer but i want all of
my
biz methods contains a piece of code for controlling the access
is there any way to force all methods to have this piece of code or
at
least a special code Attribute ?
Thanks in advance 2 1212
Implementing role-based security in a winform is the same as any other;
set the principal to something... at the simplest level see below(you
can do much more sophisticated thing if you create your own principal).
The advantage here is that a: it has runtime support built in (for the
attribute check), and b: any code (yours or 3rd party) can check the
same roles without needing to know about the specific implementation.
Note that VS2008 includes support for using the ASP.NET roles provider
inside a winform (via a web-service login).
For enforcing security on all the methods automatically (rather than
having to add the attribute) - one option would be PostSharp; it looks
like it would be trivial to add some code that simply does a Demand...
Marc
static void Main(string[] args)
{
string[] myRoles = {"GUEST", "USER"};
Thread.CurrentP rincipal = new GenericPrincipa l(
new GenericIdentity ("Fred"), myRoles);
UserMethod();
CheckManually() ;
AdminMethod();
}
[PrincipalPermis sion(SecurityAc tion.Demand, Role = "USER")]
static void UserMethod()
{
Console.WriteLi ne("User method");
}
static void CheckManually()
{
string role = "GUEST"; // dynamic...
bool isInRole = Thread.CurrentP rincipal.IsInRo le(role);
// or to demand (throwing a suitable exception if not)
PrincipalPermis sion perm = new PrincipalPermis sion(null, role);
perm.Demand();
Console.WriteLi ne(isInRole);
}
[PrincipalPermis sion(SecurityAc tion.Demand, Role = "ADMIN")]
static void AdminMethod()
{
Console.WriteLi ne("Admin method");
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cybertoast |
last post by:
i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->->properties->permissions->. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @rolename does
not work).
Is there some other command that is used to add...
|
by: islandfong |
last post by:
Hi,
I am using ASP.NET 2.0 to implement a user access control system. The idea is that I would allow users (admin) to create new role, new user, assign user to role and the role is given different privilege to access diffferent web pages. For example, the admin can have view/update/create role, however a normal user can only view the role infomation. If I want to implement the view/update/create function in the same web form, how can I...
|
by: Luqman |
last post by:
How to implement Role Enabled Security in Visual Basic 2005 Windows
Application, like we do in ASP.Net 2.0 ?
I want to use Sql Server Membership Security for Adding Roles and Users.
Can I use system.web.security in Windows Application for this purpose ?
Best Regards,
Luqman
|
by: ohmmega |
last post by:
simple question:
is there a easy way to implement different user levels (hiding buttons
and such stuff)?
regards
rené p.
|
by: parez |
last post by:
Whats the best way of implementing authorization in a win forms
application.
I mean things like show/hide or enable/disable Save button ,creating
context menus etc.
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |