473,796 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct model for role based app?

I'm familiar with membership/roles in ASP.NET 2.0. Rather than the
more common directory restriction, I need page part restrictions.
There are certain parts of my webpages that I need visible if you are
in a particular role. So maybe the "go to billing" button is only
visible if you are in "plan1" role. What is the correct method/model
to implement that type of role restriction?

Will I need to put in a conditional for each component that needs
displays dependent on a role:

if (Roles.IsUserIn Role("plan1"))
//display button
else
//don't display button

The problem with the above code is that it won't scale very well. I
may in the future want to add "plan2" to the above. So anyone is plan1
or plan2 sees the button. Plan3 doesn't however. I'd have to go find
all of the conditionals that need plan2 and update them. Is there a
better way?

Thanks,
Brett

Jan 25 '07 #1
6 1228
On my custom role provider I added:

IsInAnyRole ( string[] roles )
{

for (int i = 0 ; i < roles.length ; i++)
{
if (IsInRole(roles[i]) return true;
}

return false;
}
IsInAllRoles ( string [] roles )

{

}
Somewhere you gotta push a role (or roles) into a method.

I think I got the idea from here:
http://msdn2.microsoft.com/en-us/library/aa302401.aspx
"perplexed" <jo***@bigstrin g.comwrote in message
news:11******** **************@ h3g2000cwc.goog legroups.com...
I'm familiar with membership/roles in ASP.NET 2.0. Rather than the
more common directory restriction, I need page part restrictions.
There are certain parts of my webpages that I need visible if you are
in a particular role. So maybe the "go to billing" button is only
visible if you are in "plan1" role. What is the correct method/model
to implement that type of role restriction?

Will I need to put in a conditional for each component that needs
displays dependent on a role:

if (Roles.IsUserIn Role("plan1"))
//display button
else
//don't display button

The problem with the above code is that it won't scale very well. I
may in the future want to add "plan2" to the above. So anyone is plan1
or plan2 sees the button. Plan3 doesn't however. I'd have to go find
all of the conditionals that need plan2 and update them. Is there a
better way?

Thanks,
Brett

Jan 25 '07 #2
Thanks but what I really need is more fine grain control. If there are
three roles and content on one page is dependent on different roles,
that means I'll need three "different" checks. The method you have
will display all three pieces of content regardless of a "particular "
role. So on one page it may look like this:

if (Roles.IsUserIn Role("plan1"))
//display button1
else
//don't display button1

if (Roles.IsUserIn Role("plan2"))
//display button2
else
//don't display button2

if (Roles.IsUserIn Role("plan3"))
//display button3
else
//don't display button3

Jan 25 '07 #3


I don't understand your issue. With the method you have, and the 2 I
suggested (via the URL), then you have control

private readonly string ROLE_PLAN1 = "plan1";
private readonly string ROLE_PLAN2 = "plan2";
private readonly string ROLE_PLAN3 = "plan3";
this.button1.vi sible = Roles.IsUserInR ole ( ROLE_PLAN1 );
this.button2.vi sible = Roles.IsUserInR ole ( ROLE_PLAN2 );
this.button3.vi sible = Roles.IsUserInR ole ( ROLE_PLAN3 );

this button12.visibl e = Roles.IsInAnyRo le ( new string[] { ROLE_PLAN1 ,
ROLE_PLAN2 } ) ;
this button13.visibl e = Roles.IsInAnyRo le ( new string[] { ROLE_PLAN1 ,
ROLE_PLAN3 } ) ;

this.supersecre tbutton.visible = Roles.IsInAllRo les ( new string[] {
ROLE_PLAN1 , ROLE_PLAN2 , ROLE_PLAN3 } ) ;
...

If you need runtime ability to add buttons via roles, that's a different
issue. Doable, but more involved.

Someone correct me if I'm wrong, but there isn't any magic fairy dust, if
you have a button, and it depends on a role, somewhere you have to set the
visible property against a role/set of roles.

The 3 methods should cover the now and future needs as you add more roles.


"perplexed" <jo***@bigstrin g.comwrote in message
news:11******** **************@ v45g2000cwv.goo glegroups.com.. .
Thanks but what I really need is more fine grain control. If there are
three roles and content on one page is dependent on different roles,
that means I'll need three "different" checks. The method you have
will display all three pieces of content regardless of a "particular "
role. So on one page it may look like this:

if (Roles.IsUserIn Role("plan1"))
//display button1
else
//don't display button1

if (Roles.IsUserIn Role("plan2"))
//display button2
else
//don't display button2

if (Roles.IsUserIn Role("plan3"))
//display button3
else
//don't display button3

Jan 25 '07 #4
You can try this also:
http://msdn2.microsoft.com/en-gb/library/aa480723.aspx
"sloan" <sl***@ipass.ne twrote in message
news:ur******** ******@TK2MSFTN GP03.phx.gbl...
>

I don't understand your issue. With the method you have, and the 2 I
suggested (via the URL), then you have control

private readonly string ROLE_PLAN1 = "plan1";
private readonly string ROLE_PLAN2 = "plan2";
private readonly string ROLE_PLAN3 = "plan3";
this.button1.vi sible = Roles.IsUserInR ole ( ROLE_PLAN1 );
this.button2.vi sible = Roles.IsUserInR ole ( ROLE_PLAN2 );
this.button3.vi sible = Roles.IsUserInR ole ( ROLE_PLAN3 );

this button12.visibl e = Roles.IsInAnyRo le ( new string[] { ROLE_PLAN1 ,
ROLE_PLAN2 } ) ;
this button13.visibl e = Roles.IsInAnyRo le ( new string[] { ROLE_PLAN1 ,
ROLE_PLAN3 } ) ;

this.supersecre tbutton.visible = Roles.IsInAllRo les ( new string[] {
ROLE_PLAN1 , ROLE_PLAN2 , ROLE_PLAN3 } ) ;
..

If you need runtime ability to add buttons via roles, that's a different
issue. Doable, but more involved.

Someone correct me if I'm wrong, but there isn't any magic fairy dust, if
you have a button, and it depends on a role, somewhere you have to set the
visible property against a role/set of roles.

The 3 methods should cover the now and future needs as you add more roles.


"perplexed" <jo***@bigstrin g.comwrote in message
news:11******** **************@ v45g2000cwv.goo glegroups.com.. .
Thanks but what I really need is more fine grain control. If there are
three roles and content on one page is dependent on different roles,
that means I'll need three "different" checks. The method you have
will display all three pieces of content regardless of a "particular "
role. So on one page it may look like this:

if (Roles.IsUserIn Role("plan1"))
//display button1
else
//don't display button1

if (Roles.IsUserIn Role("plan2"))
//display button2
else
//don't display button2

if (Roles.IsUserIn Role("plan3"))
//display button3
else
//don't display button3


Jan 25 '07 #5
You can try this also:http://msdn2.microsoft.com/en-gb/library/aa480723.aspx

Great link. Thanks. It's probably about as close as I can get to what
I need.

I'm going to rethink the design of this project as well. Using the
above will slow it down. Additional role checks in the form layer will
also slow it down (initial suggestion by me). So, getting granular
role checks into the app will slow it down in general, make it more
complicated and add a lot of administration (ie coding maintenance).
I'm going to avoid being so granular just because that's practical.
It's great in theory to display this piece and that piece based on a
role or combination of roles. But unless you have a few people that
understand it really well and know how to code it, doing it alone will
greatly stretch out your project ending date.

Jan 25 '07 #6
On a sadder note, I probably won't be able to use the attribute based
authorization described in the above link. I'm on a shared box so no
access AzMan.

However, I don't want to use all of their architecture. Creating a
class that will turn on/off visbility, have controls inherit from it,
and add attributes to the config file may work ok. It will be much
simpler.

Jan 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7113
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
0
3100
by: Murray | last post by:
I am trying to develop a web based database application to manage a Scout group. I need to control the level of access different visitors to the site are allowed to different parts of the database. I need to provide public information, including some contact details from the database, to unauthenticated (non-member) users and to provide a scale of access to more information for authenticated members. The access model would be similar...
12
2238
by: Z D | last post by:
Good Morning, I was looking for some feedback, guidance, input, comments, suggestions or just general thoughts on the following: For our internal development, I'm trying to create a general, reusable security framework that is very flexible. It would have to handle both Authentication and Authorization. The access levels allowed on each 'object' would be: View/Edit/Read/Write.
2
3049
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some content based on the user's role. I wrote this to do it: if (HttpContext.Current.User.Identity.IsAuthenticated) { plLoggedIn.Visible = true;
50
6083
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Strict kills my widths!</title> </head> <body> <table style="width:400px; table-layout:fixed;">
5
4312
by: isideveloper | last post by:
I'm building a new C# web application that will provide my company some administrative operations that were previously only completed by tweaking the data in the database. 1. Encrypted password authentication 2. "Group" level permissions that allow permission overrides for specific users 3. Ability to set permissions to view, edit, and read only - by user or role. 4. Ability to set permissions based on data - certain users can only see
12
7505
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use it to reset info in a combo box. Below is some sample code for my view interface and the presenter: public interface IDevToolView
9
1725
by: Marc De Schrijver | last post by:
I'm designing an OO Model for a large application, and I have some question on how to model a particular situation; it's not directly related to C# but rather to general OO. The applicaiton will be developed in C# 2.0 though, which may have some influence on the OO model. Here's what I'm trying to model: I have a class Company, a class Publisher, a class Manufacturer and a class Distributor. Their relationships are as follows: 1. A...
3
1712
by: Froefel | last post by:
I'm trying to modem a relationship with classes and I'm having trouble finding the correct design pattern. Maybe someone with more experience knows which pattern(s) I'm looking for. Here's an explanation of what I have and in which direction I'm thinking: CLASS DESIGN ============= 1. Generic class "Company" contains general company information (name, address, reference person, phone, etc...)
0
10237
jinu1996
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...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
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...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
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();...
0
5446
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...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
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
3
2928
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.