I have a website with createuserwizard and with some roles. I have several roles and one of them is "Users". What I want is when a person creates a new account using the create user wizard I want it to give this account "Users" role automatically. How can
I do that?
Mac14
Member
46 Points
71 Posts
Giving users a role after registration
Dec 30, 2012 08:12 PM|LINK
Hello everyone!
I have a website with createuserwizard and with some roles. I have several roles and one of them is "Users". What I want is when a person creates a new account using the create user wizard I want it to give this account "Users" role automatically. How can I do that?
I am waiting for your answers
Have a great day!
eric2820
Contributor
2777 Points
1161 Posts
Re: Giving users a role after registration
Dec 30, 2012 08:40 PM|LINK
In your global.asax.cs file add a function like this:
protected void Application_PostAuthenticateRequest( object sender, EventArgs e )
{
var ctx = HttpContext.Current;
if ( ctx.Request.IsAuthenticated )
{
string[] roles = LookupRolesForUser( ctx.User.Identity.Name );
var newUser = new GenericPrincipal( ctx.User.Identity, roles );
ctx.User = Thread.CurrentPrincipal = newUser;
}
}
Of course the LookupRolesForUser function is one that you'll have to write.
This is one step that is the same for both ASP.Net and MVC.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
geniusvishal
Star
14064 Points
2788 Posts
Re: Giving users a role after registration
Dec 31, 2012 05:47 AM|LINK
Hi Mac.. Please go through the articles and threads:
http://forums.asp.net/t/1304100.aspx
http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx
http://www.asp.net/web-forms/tutorials/security/roles/assigning-roles-to-users-cs
My Website
www.dotnetvishal.com