A
Author
I have configured my asp.net 3.5 web application to use Active
Directory authentication with Forms authentication, and it's working
perfectly.
Suppose my web application identifies 3 user roles: Admin, Data Entry,
Project Manager, and they perform different tasks.
It's very common to present different functionality to different user
groups. For example, only Admin users can manage system users; Data
Entry staff cannot generate project reports, etc. Naturally, some
controls will be shown/hidden or enabled/disabled according to the
user role of the logged-in user.
Now, what is the best strategy to control such web controls? I know I
can do this (and have done this before) through if-else conditioning
like
if (user.Role == UserRoles.Admin)
{
userManagementButton.Visible = true;
projectReportGenerationButton.Visible = false;
}
else if ( blah)
{ //blah blah
}
else
{
// blah blah blah
}
, which is very a basic and straightforward approach. However, I
think this is sorta cumbersome, and thus I am interested in learning
any better strategy.
For example, for a button control, is it a good strategy to implement
our own user-role-aware button control by inheriting the Button
control? I haven't done this, but I think if I do this, then, I only
need to write such annoying and cumbersome if-else's once in the
implementation of the inherited button controls. And to use it, we
simply set its user role property. Does this make sense? Has anyone
done something like this before? Do-able? Recommendable?
Thanks a lot.
Directory authentication with Forms authentication, and it's working
perfectly.
Suppose my web application identifies 3 user roles: Admin, Data Entry,
Project Manager, and they perform different tasks.
It's very common to present different functionality to different user
groups. For example, only Admin users can manage system users; Data
Entry staff cannot generate project reports, etc. Naturally, some
controls will be shown/hidden or enabled/disabled according to the
user role of the logged-in user.
Now, what is the best strategy to control such web controls? I know I
can do this (and have done this before) through if-else conditioning
like
if (user.Role == UserRoles.Admin)
{
userManagementButton.Visible = true;
projectReportGenerationButton.Visible = false;
}
else if ( blah)
{ //blah blah
}
else
{
// blah blah blah
}
, which is very a basic and straightforward approach. However, I
think this is sorta cumbersome, and thus I am interested in learning
any better strategy.
For example, for a button control, is it a good strategy to implement
our own user-role-aware button control by inheriting the Button
control? I haven't done this, but I think if I do this, then, I only
need to write such annoying and cumbersome if-else's once in the
implementation of the inherited button controls. And to use it, we
simply set its user role property. Does this make sense? Has anyone
done something like this before? Do-able? Recommendable?
Thanks a lot.