Search code examples
asp.netsql-server-2005asp.net-membership

add user and assign role in aspnet membership through sql servers SP


Tech - asp.net 3.5, Sql server 2005

I have integrate aspnet membership for my webapplication.

I am adding some users (member) from importing excel file.

So how can I add that user and role of that user in aspnet membership tables?

NOTE - I have SP which is used to add member in DB from uploaded excel file, I have wrote insert trriger on membertable.


Solution

  • Do not insert DB records manually. Use .NET's Membership Provider's stored procedures to do that, for example aspnet_Membership_CreateUser and aspnet_Roles_CreateRole.

    But better off, use .NET's classes/methods to do that. They encapsulate the whole mechanism for you:

    First you create a user, then you (optionally) attach role(s) to.

    UPDATE December 2015

    Folks keep reading this. It's important to know that for a few years now, there is a totally different paradigm, ASP.NET Identity. please use it instead of the old Membership Provider.