473,434 Members | 1,791 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,434 software developers and data experts.

Roles in membership database

AC
Hi there. My asp.net 2.0 development website uses roles to control
access to sections of my site, configured using the asp.net
configuration tool, which is great. Except that isn't available once
published on the public, third-party hosted site. So I need to be
able to configure access through a new section of the site, available
only to admins/developers, which I'm about to write.

First off, I want to create a role in the database to represent users
who can access this area of the site - and I need to be able to do it
manually so I can test as I'm developing. I've created my new role in
my membership database by adding a row to the aspnet_Roles table and
added a user to that role by adding a row to the aspnet_UsersInRoles
table. However, Roles.GetRolesForUser() returns a zero-dimensioned
string array so I must have missed a trick somewhere ... can anyone
point me in the right direction please?

The membership database works fine in that any old user can come
along, register, gain access to members-only sections, etc., it's just
the roles-without-aspnet-config-tool I seem to be having trouble
with.

Thanks for your time,
AC

Mar 19 '07 #1
4 3244

You can't use that tool remotely as you've found out.
Here is the big 3 methods. I've wrappped them up for you.

// private List<string_toDoUserAndRoleValues = new List<string>();
ex john,admin
private void MapUsersToRoles()
{

char char1 = Convert.ToChar(",");

char[] splitter = { char1 };
foreach (string userAndRole in this._toDoUserAndRoleValues)
{

string[] splitUserNameAndRole = userAndRole.Split(splitter);

string userName = splitUserNameAndRole[0];
string roleName = splitUserNameAndRole[1];

if (!Roles.IsUserInRole (userName, roleName ))
{

Roles.AddUsersToRole(new string[] { userName } ,
roleName );
_actuallyImportedList.Add(string.Format("{0} / {1}",
userName, roleName));
}

}

}

private void CreateRole(string roleName)
{

if(!Roles.RoleExists (roleName ))
{
Roles.CreateRole(roleName);
this._allImportedRoles.Add(roleName);
}

}
private void CreateUser(string userName, string password)
{

if (null==System.Web.Security.Membership.GetUser (userName))
{
System.Web.Security.Membership.CreateUser(userName ,
password);
this._allImportedUser.Add(userName);
}

}

"AC" <an**********@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
Hi there. My asp.net 2.0 development website uses roles to control
access to sections of my site, configured using the asp.net
configuration tool, which is great. Except that isn't available once
published on the public, third-party hosted site. So I need to be
able to configure access through a new section of the site, available
only to admins/developers, which I'm about to write.

First off, I want to create a role in the database to represent users
who can access this area of the site - and I need to be able to do it
manually so I can test as I'm developing. I've created my new role in
my membership database by adding a row to the aspnet_Roles table and
added a user to that role by adding a row to the aspnet_UsersInRoles
table. However, Roles.GetRolesForUser() returns a zero-dimensioned
string array so I must have missed a trick somewhere ... can anyone
point me in the right direction please?

The membership database works fine in that any old user can come
along, register, gain access to members-only sections, etc., it's just
the roles-without-aspnet-config-tool I seem to be having trouble
with.

Thanks for your time,
AC

Mar 19 '07 #2
AC
OK so you're saying I can do it by writing something using the
Membership classes - thanks for your help. Shame I can't
circumnavigate the first stage and simply stick something straight
into the database to allow ME access but - I wouldn't want it to be
easy !!! ...

Thanks again,
AC

On Mar 19, 9:33 pm, "sloan" <s...@ipass.netwrote:
You can't use that tool remotely as you've found out.

Here is the big 3 methods. I've wrappped them up for you.

// private List<string_toDoUserAndRoleValues = new List<string>();
ex john,admin
private void MapUsersToRoles()
{

char char1 = Convert.ToChar(",");

char[] splitter = { char1 };

foreach (string userAndRole in this._toDoUserAndRoleValues)
{

string[] splitUserNameAndRole = userAndRole.Split(splitter);

string userName = splitUserNameAndRole[0];
string roleName = splitUserNameAndRole[1];

if (!Roles.IsUserInRole (userName, roleName ))
{

Roles.AddUsersToRole(new string[] { userName } ,
roleName );
_actuallyImportedList.Add(string.Format("{0} / {1}",
userName, roleName));
}

}

}

private void CreateRole(string roleName)
{

if(!Roles.RoleExists (roleName ))
{
Roles.CreateRole(roleName);
this._allImportedRoles.Add(roleName);
}

}

private void CreateUser(string userName, string password)
{

if (null==System.Web.Security.Membership.GetUser (userName))
{
System.Web.Security.Membership.CreateUser(userName ,
password);
this._allImportedUser.Add(userName);
}

}

"AC" <andy.coll...@gmail.comwrote in message

news:11**********************@p15g2000hsd.googlegr oups.com...
Hi there. My asp.net 2.0 development website uses roles to control
access to sections of my site, configured using the asp.net
configuration tool, which is great. Except that isn't available once
published on the public, third-party hosted site. So I need to be
able to configure access through a new section of the site, available
only to admins/developers, which I'm about to write.
First off, I want to create a role in the database to represent users
who can access this area of the site - and I need to be able to do it
manually so I can test as I'm developing. I've created my new role in
my membership database by adding a row to the aspnet_Roles table and
added a user to that role by adding a row to the aspnet_UsersInRoles
table. However, Roles.GetRolesForUser() returns a zero-dimensioned
string array so I must have missed a trick somewhere ... can anyone
point me in the right direction please?
The membership database works fine in that any old user can come
along, register, gain access to members-only sections, etc., it's just
the roles-without-aspnet-config-tool I seem to be having trouble
with.
Thanks for your time,
AC

Mar 19 '07 #3

I actually wrote a .txt file reader, which reads the lines, and calls the
code below.

One file has users
One file has roles
One file has user-roles relationships.

With the code below, the other code would be simple.

Then I can deploy a new website or update one, with the creation of a few
..txt files.

roles.txt
SuperAdmin
Admin
RegularUser
Guest
users.txt
John,jpassword123
Mary,mpassword234
user_role.txt
John,SuperAdmin
Mary,Admin
John,RegularUser
Mary,RegularUser

"AC" <an**********@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
OK so you're saying I can do it by writing something using the
Membership classes - thanks for your help. Shame I can't
circumnavigate the first stage and simply stick something straight
into the database to allow ME access but - I wouldn't want it to be
easy !!! ...

Thanks again,
AC

On Mar 19, 9:33 pm, "sloan" <s...@ipass.netwrote:
You can't use that tool remotely as you've found out.

Here is the big 3 methods. I've wrappped them up for you.

// private List<string_toDoUserAndRoleValues = new
List<string>();
ex john,admin
private void MapUsersToRoles()
{

char char1 = Convert.ToChar(",");

char[] splitter = { char1 };

foreach (string userAndRole in this._toDoUserAndRoleValues)
{

string[] splitUserNameAndRole =
userAndRole.Split(splitter);

string userName = splitUserNameAndRole[0];
string roleName = splitUserNameAndRole[1];

if (!Roles.IsUserInRole (userName, roleName ))
{

Roles.AddUsersToRole(new string[] { userName } ,
roleName );
_actuallyImportedList.Add(string.Format("{0} / {1}",
userName, roleName));
}

}

}

private void CreateRole(string roleName)
{

if(!Roles.RoleExists (roleName ))
{
Roles.CreateRole(roleName);
this._allImportedRoles.Add(roleName);
}

}

private void CreateUser(string userName, string password)
{

if (null==System.Web.Security.Membership.GetUser (userName))
{
System.Web.Security.Membership.CreateUser(userName ,
password);
this._allImportedUser.Add(userName);
}

}

"AC" <andy.coll...@gmail.comwrote in message

news:11**********************@p15g2000hsd.googlegr oups.com...
Hi there. My asp.net 2.0 development website uses roles to control
access to sections of my site, configured using the asp.net
configuration tool, which is great. Except that isn't available once
published on the public, third-party hosted site. So I need to be
able to configure access through a new section of the site, available
only to admins/developers, which I'm about to write.
First off, I want to create a role in the database to represent users
who can access this area of the site - and I need to be able to do it
manually so I can test as I'm developing. I've created my new role in
my membership database by adding a row to the aspnet_Roles table and
added a user to that role by adding a row to the aspnet_UsersInRoles
table. However, Roles.GetRolesForUser() returns a zero-dimensioned
string array so I must have missed a trick somewhere ... can anyone
point me in the right direction please?
The membership database works fine in that any old user can come
along, register, gain access to members-only sections, etc., it's just
the roles-without-aspnet-config-tool I seem to be having trouble
with.
Thanks for your time,
AC


Mar 20 '07 #4
On 19 Mar 2007 13:56:34 -0700, AC wrote:
Hi there. My asp.net 2.0 development website uses roles to control
access to sections of my site, configured using the asp.net
configuration tool, which is great. Except that isn't available once
published on the public, third-party hosted site.
You might be interested in this:

http://msdn2.microsoft.com/en-us/library/aa478947.aspx
Mar 26 '07 #5

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

Similar topics

1
by: ijoxley | last post by:
Hi I'm in the middle of implementing ASP.NET membership and role-based authentication using the new ASP.NET 2.0 Membership and Roles classes/database and was stuck on the following: When...
0
by: Jack | last post by:
Hello, I need some help in getting my simple web app to work. I can't seem to get the configuration of the Membership/Roles working by pointing my website to a SQL 2005 database as opposed to...
5
by: JP.Gantlin | last post by:
I want to have a login page where the new user self-registers, giving some simple info like Real Estate Agent #. Do I need to used the membershiop/roles thing, or profiles? Are profiles part...
1
by: =?Utf-8?B?TWFya0F1cml0?= | last post by:
Im trying to help a friend who is attempting to deploy an asp.net 2.0 app. She wants to use the membership/role system, and the necessary database and its tables, etc, exist in the sql server 2000...
2
by: StinkyDuck | last post by:
Hello, I am relatively new to ASP.NET 2.0 and have been reading a book and going through some articles on the internet. When looking for information regarding membership and roles, I see lots...
1
by: =?Utf-8?B?ZVByaW50?= | last post by:
Asp.Net v2.0 I have created a web application and I am using it from a single website and database. The web application has different ‘portals’ – each independent and I am using the...
2
by: Vincent | last post by:
Hi, When the application doesn't use Roles, this configuration (web.config) works: <configuration> <connectionStrings> <clear/> <add name="myconn" connectionString="Data...
2
by: Nathan Sokalski | last post by:
When I call System.Web.Security.Roles.GetRolesForUser() it returns no results even though I have roles associated with the currently logged in user. I am able to get the username by calling...
2
by: Nathan Sokalski | last post by:
When I call System.Web.Security.Roles.GetRolesForUser() it returns no results (an array of length 0) even though I have roles associated with the currently logged in user. I am able to get the...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.