473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Roles question

I am writing an application using the ASP.NET Configuration Roles and
Users.

The problem I have, in my C# I need to work out which type of user just
logged in. I am currently using:

string[] role = Roles.GetRolesForUser();

This give me a string "Administrator" etc.

My C# code looks like this:

switch(userType)
{
case "Administrator":
//Do soemthing

//and so on...
}

Has anyone come up with a better way for doing this?

The problems I see with this, if the Role is renamed (would be deleted
and recreated to be called "Admin" for example or a new Role is added.

Any help / advice on this would be appreciated.

Regards,

Steven
*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '06 #1
5 1358
Steven,

Do you allow more than one role per person? If you do, then you need to
account for that, and a switch statement won't handle that.

If the role is renamed, then you have to change your code. I mean,
there has to be some level of consistency somewhere.

If you want, you should define aliases for your roles that you will
always use, that are linked to whatever descriptive names you give them.
However, if you use code based security, it doesn't really help, since the
name of your role has to match with the role that you specify in the
attribute.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
I am writing an application using the ASP.NET Configuration Roles and
Users.

The problem I have, in my C# I need to work out which type of user just
logged in. I am currently using:

string[] role = Roles.GetRolesForUser();

This give me a string "Administrator" etc.

My C# code looks like this:

switch(userType)
{
case "Administrator":
//Do soemthing

//and so on...
}

Has anyone come up with a better way for doing this?

The problems I see with this, if the Role is renamed (would be deleted
and recreated to be called "Admin" for example or a new Role is added.

Any help / advice on this would be appreciated.

Regards,

Steven
*** Sent via Developersdex http://www.developersdex.com ***

Jan 4 '06 #2
Yes a user can belong to more than one group.

Is there an alternative to using code based security, or am I gonna have
to accept a trade off?

I do take your point on board regarding users belonging to more than one
group. I might revisit this and simply setup one user with one role.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '06 #3
Steven,

There are alternatives, but honestly, why use them when it is baked into
the framework? It's kind of foolish to try and write your own code which
you have to test, debug, maintain, blah, blah, blah.

And even if you don't use role-based security, the issue still remains,
your code isn't psychic. It can't tell if you add new roles which have
specific meanings unless you tell it so.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
Yes a user can belong to more than one group.

Is there an alternative to using code based security, or am I gonna have
to accept a trade off?

I do take your point on board regarding users belonging to more than one
group. I might revisit this and simply setup one user with one role.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***

Jan 4 '06 #4
Maybe I am missing soemthing here.

I want to avoid re-inventing the wheel. Ideally, I want to use the
inbuilt security features completely.

My application allows different users varied access on my app, which is
great. But, the problem is, if "Role1" logs in, I need to filter some
data being returned. If "Role" logs in, same again, some filter on the
data.

Is this possible using only the inbuilt security features, or do I have
to add some C# code to cater for problems like this?

My feeling is that code is required on top of the Roles for my
particular problem, and if thats the case, was looking for suggestions
on how to make this as easy as possible.

Thanks again for the help.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '06 #5
Steven,
Yes, you will need to use some code, but not that much.

You basically do what you have to do. However, your original question
was about what to do when you change the names of the roles, which is what
most of my responses have been referring to.

Basically, you get the roles, and can check what to return based on
those roles. However, the framework will handle the assigning of the roles
for you (in ASP.NET configuration roles), so you shouldn't have to worry
about that part.

What you ^could^ do is have your functions that return data marked with
the PrincipalPermission attribute. You can specify the roles that are
allowed to access the function, and if someone tries to access the function
and is not in the role, then a SecurityException will be thrown.

This would require you to split your functions out into more intricate
groups, but would make security easy.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:OW*************@TK2MSFTNGP09.phx.gbl...
Maybe I am missing soemthing here.

I want to avoid re-inventing the wheel. Ideally, I want to use the
inbuilt security features completely.

My application allows different users varied access on my app, which is
great. But, the problem is, if "Role1" logs in, I need to filter some
data being returned. If "Role" logs in, same again, some filter on the
data.

Is this possible using only the inbuilt security features, or do I have
to add some C# code to cater for problems like this?

My feeling is that code is required on top of the Roles for my
particular problem, and if thats the case, was looking for suggestions
on how to make this as easy as possible.

Thanks again for the help.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***

Jan 4 '06 #6

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

Similar topics

4
by: Marty Underwood | last post by:
Okay the subject line explains a scenario I just had to tackle but I am looking for a better way. The current way: 1) Use forms authentication. 2) Query Active Directory and bind to a user...
1
by: Charles | last post by:
Hello, I tried posting this yesterday, and I have not seen it yet this morning. Thinking that something went wrong getting this question posted I am posting it again. Sorry if this does end up...
5
by: hansiman | last post by:
Following http://aspnet.4guysfromrolla.com/articles/082703-1.aspx I've set up roles authentication for my web application. User's roles are registered by: HttpContext.Current.User = _ New...
5
by: Jonathan Allen | last post by:
Is this the correct way to use application roles? Public Function GetDBConnection() As SqlConnection Dim oCon As New SqlConnection(myConnectionString) oCon.Open() Using oCmd As SqlCommand =...
2
by: Francis Reed | last post by:
Hi I haven a question concerning roles and membership in asp.net 2.0. I work for an online university, and we would like to implement role based security for our portal. Currently our university...
9
by: Mike Hofer | last post by:
BACKGROUND: We've designed a Website for a client that will be deployed across multiple physical locations. The site will be hosted from a corporate NOC, and administered by the IT group there. ...
3
by: rudolf.ball | last post by:
Dear NG, I plan to have a Datagrid in ASP.NET 2.0, with Users in Rows and Roles in Columns, eg. RoleA RoleB RoleC Bob x x Sue x ...
0
by: sidhuasp | last post by:
Hi everyone I am using a mainmenu witeh sitemap provider with folowing sitemap <siteMapNode> <siteMapNode url="" title="Master Data" description="Enter Master data" roles ="Admin,PM"> ...
7
by: MyndPhlyp | last post by:
I've been combing through Google trying to find the answer but not luck. I'm using Forms authentication. Determining what Roles the current user is in was the easy part (User.IsInRole). But how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...

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.