473,512 Members | 15,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

design guidance please :user controls and centralizing roles-related display stuff

I'm looking for some design guidance on a collection of projects I'm working
on.

The project involves a bunch of websites constructed out of a collection of
user controls. Different user populations with different access rights and
"roles" will be visiting the site. I will be using ASP.NET 2.0's membership,
roles, and profiles stuff to manage access.

User controls need to be visible or not visible depending on user role. In
some cases, one user role will see one "facet" of a control, while another
user role will see a different aspect of it.

The user controls are often going to be placed at runtime, and have their
properties adjusted at runtime.

What I am wondering now is the best way to centralize the code that manages
the display of these user controls based on role. What I don't want is
"if-else" junk spread throughout my code.

The project is large but not huge, and I am the sole developer for the
project. I have a few ideas for how this might work.

One might be to write a huge function: public static bool IsElementDisplayed
(string roleName, string userControlName) and have visibility of various
elements constantly checking this.

Another might be to use some form of inheritance. User controls can't
inherit from each other, but maybe they can inherit functionality from
somewhere else.

Another might be to encode this knowledge in some kind of structured data. A
database would be a disaster, but XML might be better.

Any suggestions and guidance out there?

Thanks,
-KF
..
Dec 25 '06 #1
8 1686
Hello KF,

As for the role based user-interface, I think there're two possible
scenarios:

** all the controls be put on the page and you control the visibility
dynamically

** the page's layout and controls constructure is not determined at
design-time on page. All the usercontrols are dynamically created and added
into page/container at runtime(based on some structure info from database
or in configuration file).

I assume you're using the second approach, correct? If so, since dynamic
controls need to be created and added into page control structure in each
page request and to make sure all the control lifecycle features works
well, it is recommended that the dynamic control instancing code be put in
Page's Init event(or load). Then, if you want to make the control
structure initializing code contralized, you can consider the following
approaches:

** define a helper class which parsing the configuration schema from
database or xml configuration file and create dynamic controls and add it
into page(get the reference of the page at its construct time). and this
class will be used in each page(which need such dynamic role based UI )'s
Init event.

** Define a base page class and override Page's OnInit methods and add the
dynamic UI parsing and constructing code logic there. And those concrete
pages which need dynamic role based UI can derive from this base page class.

What's your opinion or have you any other ideas on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 25 '06 #2
Lot of ways to skin a cat on this one. I'd consider a Generic List of type
"ControlDisplay" which would be a small class that describes each control's
layout and display characteristics for a specific role. The key to the List
could be something like a concatenation of the site + controlId +role (or
something to that effect).
Then, when you are about to add a dynamic control to a page, you need only
look up the site+controlId in your List (which could be stored as static in
Global), compare to the current user's role(s), and you would have everything
you need for your display business logic.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ke*****@nospam.nospam" wrote:
I'm looking for some design guidance on a collection of projects I'm working
on.

The project involves a bunch of websites constructed out of a collection of
user controls. Different user populations with different access rights and
"roles" will be visiting the site. I will be using ASP.NET 2.0's membership,
roles, and profiles stuff to manage access.

User controls need to be visible or not visible depending on user role. In
some cases, one user role will see one "facet" of a control, while another
user role will see a different aspect of it.

The user controls are often going to be placed at runtime, and have their
properties adjusted at runtime.

What I am wondering now is the best way to centralize the code that manages
the display of these user controls based on role. What I don't want is
"if-else" junk spread throughout my code.

The project is large but not huge, and I am the sole developer for the
project. I have a few ideas for how this might work.

One might be to write a huge function: public static bool IsElementDisplayed
(string roleName, string userControlName) and have visibility of various
elements constantly checking this.

Another might be to use some form of inheritance. User controls can't
inherit from each other, but maybe they can inherit functionality from
somewhere else.

Another might be to encode this knowledge in some kind of structured data. A
database would be a disaster, but XML might be better.

Any suggestions and guidance out there?

Thanks,
-KF
..
Dec 25 '06 #3
Thank you, Peter. Very helpful.

Could I ask you to elaborate just a bit on what you're thinking about when
you suggest "....that describes each control's layout and display
characteristics for a specific role"?

I'm curious to what extent you're thinking the layout and display
characteristics could/should be described in such a lookup class.

I am also curious if there is a "special" characteristic or quality of the
Generic List/Generic that I am not catching here that might make it
especially useful for this application. I am fairly new to C#, lists,
generics, OO, etc and the subtleties of good design is a long process.

Thanks again for your suggestion,
-KF
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:16**********************************@microsof t.com...
Lot of ways to skin a cat on this one. I'd consider a Generic List of type
"ControlDisplay" which would be a small class that describes each
control's
layout and display characteristics for a specific role. The key to the
List
could be something like a concatenation of the site + controlId +role (or
something to that effect).
Then, when you are about to add a dynamic control to a page, you need only
look up the site+controlId in your List (which could be stored as static
in
Global), compare to the current user's role(s), and you would have
everything
you need for your display business logic.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ke*****@nospam.nospam" wrote:
>I'm looking for some design guidance on a collection of projects I'm
working
on.

The project involves a bunch of websites constructed out of a collection
of
user controls. Different user populations with different access rights
and
"roles" will be visiting the site. I will be using ASP.NET 2.0's
membership,
roles, and profiles stuff to manage access.

User controls need to be visible or not visible depending on user role.
In
some cases, one user role will see one "facet" of a control, while
another
user role will see a different aspect of it.

The user controls are often going to be placed at runtime, and have their
properties adjusted at runtime.

What I am wondering now is the best way to centralize the code that
manages
the display of these user controls based on role. What I don't want is
"if-else" junk spread throughout my code.

The project is large but not huge, and I am the sole developer for the
project. I have a few ideas for how this might work.

One might be to write a huge function: public static bool
IsElementDisplayed
(string roleName, string userControlName) and have visibility of various
elements constantly checking this.

Another might be to use some form of inheritance. User controls can't
inherit from each other, but maybe they can inherit functionality from
somewhere else.

Another might be to encode this knowledge in some kind of structured
data. A
database would be a disaster, but XML might be better.

Any suggestions and guidance out there?

Thanks,
-KF
..

Dec 26 '06 #4
Ken,
Well at a minimum you would have a ShowControl boolean that would describe
whether the control should be displayed, based on the "role" provided. I
don't know what other characteristics you need (positioning, etc).

The Generic List could be a Hashtable. Generics simple provide a strongly
typed Collection and avoid the overhead of boxing to and from type object in
a "1.1" style collection.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Ken Fine" wrote:
Thank you, Peter. Very helpful.

Could I ask you to elaborate just a bit on what you're thinking about when
you suggest "....that describes each control's layout and display
characteristics for a specific role"?

I'm curious to what extent you're thinking the layout and display
characteristics could/should be described in such a lookup class.

I am also curious if there is a "special" characteristic or quality of the
Generic List/Generic that I am not catching here that might make it
especially useful for this application. I am fairly new to C#, lists,
generics, OO, etc and the subtleties of good design is a long process.

Thanks again for your suggestion,
-KF
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:16**********************************@microsof t.com...
Lot of ways to skin a cat on this one. I'd consider a Generic List of type
"ControlDisplay" which would be a small class that describes each
control's
layout and display characteristics for a specific role. The key to the
List
could be something like a concatenation of the site + controlId +role (or
something to that effect).
Then, when you are about to add a dynamic control to a page, you need only
look up the site+controlId in your List (which could be stored as static
in
Global), compare to the current user's role(s), and you would have
everything
you need for your display business logic.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ke*****@nospam.nospam" wrote:
I'm looking for some design guidance on a collection of projects I'm
working
on.

The project involves a bunch of websites constructed out of a collection
of
user controls. Different user populations with different access rights
and
"roles" will be visiting the site. I will be using ASP.NET 2.0's
membership,
roles, and profiles stuff to manage access.

User controls need to be visible or not visible depending on user role.
In
some cases, one user role will see one "facet" of a control, while
another
user role will see a different aspect of it.

The user controls are often going to be placed at runtime, and have their
properties adjusted at runtime.

What I am wondering now is the best way to centralize the code that
manages
the display of these user controls based on role. What I don't want is
"if-else" junk spread throughout my code.

The project is large but not huge, and I am the sole developer for the
project. I have a few ideas for how this might work.

One might be to write a huge function: public static bool
IsElementDisplayed
(string roleName, string userControlName) and have visibility of various
elements constantly checking this.

Another might be to use some form of inheritance. User controls can't
inherit from each other, but maybe they can inherit functionality from
somewhere else.

Another might be to encode this knowledge in some kind of structured
data. A
database would be a disaster, but XML might be better.

Any suggestions and guidance out there?

Thanks,
-KF
..


Dec 26 '06 #5
Thanks for bearing with me, Peter. I want to continue to explore this idea a
little further, and I hope you'll allow me a little more public embarassment
here.

So one interpretation of what you've been suggesting is to make a small
class -- let's call it UwnControl -- and attach various properties to that
class that describe name and visibility. And then I could conceivably write
code that would instantiate class instances, one for each control name that
I want to check for visiblity:
UwnControl uwnc = new UwnControl();
uwnc.App_Page_ControlName = inthemedia_overviewdotaspx_admininterface;
uwnc.IsVisibleToAdmins = true;
uwnc.IsVisibleToHoldersOfUwNetIds = false;
uwnc.IsVisibleToPublic = false;

UwnControl uwnc2 = new UwnControl();
uwnc2.App_Page_ControlName = inthemedia_overviewdotaspx_publicoverview;
uwnc2.IsVisibleToAdmins = true;
uwnc2.IsVisibleToHoldersOfUwNetIds = true;
uwnc2.IsVisibleToPublic = true;

And then I could put all of those in objects in a type-safe List, and then
do lookups against the list by name in conjunction with a function that
would evaluate and return whether a given control should be visible to a
given role or not.

If I've misunderstood you -- particularly in terms of building a collection
of simple objects as shown above -- then it's possible that this fairly
simple solution will perform badly in production, and that's why I'm running
this past you again.

I like the verbosity of using a collection of objects versus a collection of
other datatypes: it's very obvious what the data says and does.

If there are better and more elegant ways to manage this while still
retaining the general simplicity of the approach you suggested initially,
please let me know. If anyone else has thoughts or insults, feel free to
chime in.

-KF

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:62**********************************@microsof t.com...
Ken,
Well at a minimum you would have a ShowControl boolean that would describe
whether the control should be displayed, based on the "role" provided. I
don't know what other characteristics you need (positioning, etc).

The Generic List could be a Hashtable. Generics simple provide a strongly
typed Collection and avoid the overhead of boxing to and from type object
in
a "1.1" style collection.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Ken Fine" wrote:
>Thank you, Peter. Very helpful.

Could I ask you to elaborate just a bit on what you're thinking about
when
you suggest "....that describes each control's layout and display
characteristics for a specific role"?

I'm curious to what extent you're thinking the layout and display
characteristics could/should be described in such a lookup class.

I am also curious if there is a "special" characteristic or quality of
the
Generic List/Generic that I am not catching here that might make it
especially useful for this application. I am fairly new to C#, lists,
generics, OO, etc and the subtleties of good design is a long process.

Thanks again for your suggestion,
-KF
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:16**********************************@microsof t.com...
Lot of ways to skin a cat on this one. I'd consider a Generic List of
type
"ControlDisplay" which would be a small class that describes each
control's
layout and display characteristics for a specific role. The key to the
List
could be something like a concatenation of the site + controlId +role
(or
something to that effect).
Then, when you are about to add a dynamic control to a page, you need
only
look up the site+controlId in your List (which could be stored as
static
in
Global), compare to the current user's role(s), and you would have
everything
you need for your display business logic.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ke*****@nospam.nospam" wrote:

I'm looking for some design guidance on a collection of projects I'm
working
on.

The project involves a bunch of websites constructed out of a
collection
of
user controls. Different user populations with different access rights
and
"roles" will be visiting the site. I will be using ASP.NET 2.0's
membership,
roles, and profiles stuff to manage access.

User controls need to be visible or not visible depending on user
role.
In
some cases, one user role will see one "facet" of a control, while
another
user role will see a different aspect of it.

The user controls are often going to be placed at runtime, and have
their
properties adjusted at runtime.

What I am wondering now is the best way to centralize the code that
manages
the display of these user controls based on role. What I don't want is
"if-else" junk spread throughout my code.

The project is large but not huge, and I am the sole developer for the
project. I have a few ideas for how this might work.

One might be to write a huge function: public static bool
IsElementDisplayed
(string roleName, string userControlName) and have visibility of
various
elements constantly checking this.

Another might be to use some form of inheritance. User controls can't
inherit from each other, but maybe they can inherit functionality from
somewhere else.

Another might be to encode this knowledge in some kind of structured
data. A
database would be a disaster, but XML might be better.

Any suggestions and guidance out there?

Thanks,
-KF
..



Dec 27 '06 #6
Hi KF,

I think those custom class(represent each control's visibility info against
roles) should be made as lightweight as possible. Also, since these object
List should be generated from a configuration file(XML file that store the
role based control/page layout info), you can cache those list in
Application cache and make the cache dependent on the XML configuration
file. Thus, whenever the xml file is modified, the cached list will be
invalidated. And the list should be accessed by an wrapper class which use
on-demand patter to initialize the list. e.g.

public list GetList()
{
if(Cache["_list"] == null)
{
GenerateListFromConfigurationFile();
}

return Cache["_list"];
}

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 27 '06 #7
This is very good, thank you Steven.

So I need just one other code sample or example before I run off this and
actualize it: can you (or someone) give me a brief example of how you could
use references in XML to instantiate a list, as you seem to describe?

Will those XML entries each instantiate a lightweight object, and then
you'll have a list of objects, or were you contemplating some other data
structure as "holders" of the information?

Thanks again. I really appreciate the opportunity to learn these practices.

-KF
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:wa**************@TK2MSFTNGHUB02.phx.gbl...
Hi KF,

I think those custom class(represent each control's visibility info
against
roles) should be made as lightweight as possible. Also, since these object
List should be generated from a configuration file(XML file that store the
role based control/page layout info), you can cache those list in
Application cache and make the cache dependent on the XML configuration
file. Thus, whenever the xml file is modified, the cached list will be
invalidated. And the list should be accessed by an wrapper class which use
on-demand patter to initialize the list. e.g.

public list GetList()
{
if(Cache["_list"] == null)
{
GenerateListFromConfigurationFile();
}

return Cache["_list"];
}

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Dec 27 '06 #8
Thanks for your reply KF,

For example of generating a list of class objects from XML file, you can
simply use the .net framework's XML Serialization feature. Generally,
simple custom class or generic collection class support XML serialization.
e.g., the following code demonstrate serialize a custom object's List into
xml file and deserialize it back to memory:
===============================
static void Serialize()
{
XmlSerializer serializer = new
XmlSerializer(typeof(List<TestClass>));

List<TestClassobjs = new List<TestClass>();

for (int i = 0; i < 5; i++)
{
TestClass to = new TestClass();
to.ID = "id_" + i;
to.Visible = i % 2 == 0 ? true : false;

objs.Add(to);
}

StreamWriter sw = new StreamWriter("output.xml", false,
System.Text.Encoding.UTF8);

serializer.Serialize(sw, objs);

sw.Close();
}

static void Deserialize()
{
XmlSerializer serializer = new
XmlSerializer(typeof(List<TestClass>));

StreamReader sr = new StreamReader("output.xml",
System.Text.Encoding.UTF8);

List<TestClassobjs = serializer.Deserialize(sr) as
List<TestClass>;

sr.Close();
foreach(TestClass to in objs)
{
Console.WriteLine("id: {0}, visible: {1}", to.ID,
to.Visible);
}
}
===============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.



Dec 29 '06 #9

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

Similar topics

5
1947
by: jqpdev | last post by:
Hello all... I'm coming from a Borland Delphi background. Delphi has a specific component called a Data Module. In the designer the Data Module behaves like a windows form. A developer can...
2
1467
by: Tim Marsden | last post by:
Hi, Please excuse me, I am complete ASP novice. I use VB.NET in VS 2003. I am trying to achieve the following. Display a list of items, this list needs to be user specific, so my first...
3
2018
by: tshad | last post by:
I am playing with GenericPrincipal classes and am using a sample program to test it. The problem is that even though I set the roles (which shows the roles in the Context.User as being there),...
4
2203
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
2
2744
by: Annie | last post by:
Hello guys, I have set the MEMBERSHIP, ROLEMANAGER and PROFILE in my config file as below. I just want to use my own sql server 2000 table instead of MSDB.
1
1132
by: Rusty Hill | last post by:
In ASP.net 2.0 I need to create a scheduling page that allows my users to book/schedule/reserve six different surgery rooms. What the design calls for is one screen that has the daily schedule on...
1
8643
by: Ricardo Luceac | last post by:
Hi all... I'm been working with asp.net and I use the membership and roles providers that are built in controls.. Now I need do do an windows application, I've not found these controls in...
14
3245
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
2
1872
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
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...
0
7432
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...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4743
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...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
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 ...
0
452
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...

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.