Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Add user to role on signup

Reply
Thread Tools

Add user to role on signup

 
 
^MisterJingo^
Guest
Posts: n/a
 
      06-04-2006
Hi all,

I've been searching the net for a way to programatically add a user to
a role on successful registration. Not finding anything useful I
decided to experiment and came up with the following. Using the
SQLprovider for membership/roles and the createUserWizard:

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs
e)
{
Roles.AddUserToRole(CreateUserWizard1.UserName, "User");
}

This seems to work fine, but wanted to check if it was ok to do it
this way.

Thanks.

 
Reply With Quote
 
 
 
 
PeterKellner
Guest
Posts: n/a
 
      06-05-2006
On 4 Jun 2006 10:21:07 -0700, "^MisterJingo^" <(E-Mail Removed)>
wrote:

>Hi all,
>
> I've been searching the net for a way to programatically add a user to
>a role on successful registration. Not finding anything useful I
>decided to experiment and came up with the following. Using the
>SQLprovider for membership/roles and the createUserWizard:
>
>protected void CreateUserWizard1_CreatedUser(object sender, EventArgs
>e)
> {
> Roles.AddUserToRole(CreateUserWizard1.UserName, "User");
>}
>
> This seems to work fine, but wanted to check if it was ok to do it
>this way.
>
>Thanks.


If you look at the asp.net sample apps, they create the users in the
global.asax file. That is the pattern I follow. Here is the code
from a sample app:

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>



<script runat="server">

void Application_Start(Object sender, EventArgs e) {
// Code that runs on application startup
if (Roles.Enabled)
{
if (!Roles.RoleExists("ProjectAdministrator"))
{
Roles.CreateRole("ProjectAdministrator");
}
if (!Roles.RoleExists("ProjectManager"))
{
Roles.CreateRole("ProjectManager");
}

if (!Roles.RoleExists("Consultant"))
{
Roles.CreateRole("Consultant");
}
}


}

void Application_End(Object sender, EventArgs e) {
// Code that runs on application shutdown

}

Peter Kellner
http://peterkellner.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AzMan Role Based Security vs. ASP.NET Role Based Security Kursat ASP .Net Security 1 05-07-2007 01:33 PM
Banned on signup! RObErT_RaTh The Lounge 71 10-15-2005 10:38 AM
What XML is supposed to be sent back after WPS signup? white_cs Wireless Networking 6 07-11-2005 01:31 AM
Role-Based Security: ACLs and Role Hierarchies Liet Kynes ASP .Net 0 11-26-2003 08:08 AM
Role-based security: Access the role of current user Jesper Stocholm ASP .Net 2 08-23-2003 06:59 PM



Advertisments