I like to write about a topic before I give a presentation. Writing is my way of organizing random thoughts into an arbitrary collection of opinions.
When I signed up to do a presentation at the last local code camp, I got behind on writing about membership and role providers in ASP.NET 2.0. I finally finished the writing this weekend (Part I, Part II).
Miguel Castro also covered membership features at the last code camp. Miguel concentrated on the login controls and UI customization while I stuck more to the configuration and other details. Miguel knows a great deal about ASP.NET server controls –just listen to his .NET Rocks appearance. Two thumbs up!
Comments
Thanx...
But I m looking for an article which shows that how to create your own custome membership provider.... And there's a lot of links and material available on this topic...
But none of them shows how to use your existing database.... rather than using the .Net's default database.
If I have my existing database in the access or sql server... n it has user table with the field username, password n their roles then how to use it to gain the features of this membership provider class....
If u require n e further info... then let me know...
N if u know n e other relevant materials or links or urself having knowledge of it... then pl let me know about that too.
my email id - vishal_027@yahoo.co.in
thnx.....
msdn.microsoft.com/.../default.asp
a) the usage of RoleManager is an implementation detail. Context.User is a more general concept.
b) Roles.IsUserInRole calls RolePrincipal.IsInRole under the hood, anyway.
good article!
SqlTableProfileProvider
and this is the download link:
Info at ASP.NET
Good info in the refered samples..
Mike
_________________
nz website design
There's more information about membership profile providers here:
weblogs.asp.net/.../435038.aspx
and this is a good download link for a SQL table provider:
www.asp.net/.../samp_profiles.aspx
Good info in the refered samples..
Mike
______________________
http://www.ediy.co.nz
Great artical.
You mention that the configuration of the provider is on the machine.config. which mean all site on that machine must use the same provider.
What about multiple provider on the same machine?
For example, I wrote a custom provider for my site but other site on the same machine use the default provider.
10X
Niro
If that's not the case then email or post the specific error message and I can try to help.
I would like to add some properties, like the display name to use instead of username for the welcomeLabel, or others properties like employeeID.
I not finding the right way... can anyone help me?
Have you looked at the Profile features? http://www.odetocode.com/Articles/440.aspx
Here's the scenario:
Using SQL Express after running the aspnet_regsql wizard for both the SqlMembershipProvider and SqlRoleProvider.
I've entered some users and roles, and everything looks good on my development machine. Now I want to export that stuff to a live server that I have also run the aspnet_regsql wizard on.
The data does not copy nicely with SQL Server Management Studio because of foreign key errors. There seems to be no way to easily copy the data without disabling foreign keys.
Surely there is a solution for this common scenario?
Thanks.
I'm starting to write some ASP .Net 2.0 applications and your articles are very useful.
But is it possible to do 'single sign on'? Is it possible to customized the login controls? (e.g. when a specific user account tried several times. an alert will send to admin?)
More, must I use access, sql or AD? Any provider for LDAP?
Thx for your attention.
You can certainly customize the login control to send an alert. As for access, it's tough to say without more requirements.
There is some info on MSDN:
msdn.microsoft.com/.../singlesignon.asp?frame=true
thx for the article. I'm studying it now. However, so, there're no LDAP membership provider for asp.net 2.0 yet?
it`s a very good article. Please could you explain me, how to use the MembershipUser-Object that is returned by the CreateUser method. I dont understand the functionality of this object. Do i need this object for DB-Access or rolemanagement?
thx for answering
Nico
You would expect to see the login control with username, password, and companykey. A connectionstring will be derived from the companykey.
How do I put this connection string to work with the .Net built in Membership components. The only way I know is to preset this connectionstring in web.config and associate it with the provider.
I appreciate with any pointers.
Lance
The connection strings for 2.0 (even for the providers) have moved into the connectionStrings section of the web.config file.
A programatic way to change passwords has to be possible without storing user passwords in another way, simply to have them available to change the password.
I’m writing you to suggest a product similar to MS Authorization Manager, that I have written and published as open source at: .NET Sql Authorization Manager (NetSqlAzMan). http://netsqlazman.sourceforge.net
Here a short description of NetSqlAzMan:
The .NET Sql Authorization Manager allows you to set "Item-based" permissions for Authorization Manager-enabled Microsoft .NET 2.0 applications (Smart client & Web apps). Storage reside on a DataBase MS Sql Server (2000/MSDE/2005/Express).
Andrea.
This is the configuration I have:
<roleManager enabled="true"
cacheRolesInCookie="false"
defaultProvider="RoleManagerAzManProvider"
cookieName=".ASPXROLES"
cookiePath="/"
cookieTimeout="1"
cookieRequireSSL="false"
cookieSlidingExpiration="false"
createPersistentCookie="false"
cookieProtection="All">
<providers >
<add connectionStringName="LocalPolicyStore" applicationName="Logica" name="RoleManagerAzManProvider" type="System.Web.Security.AuthorizationStoreRoleProvider, System.Web, Version=2.0.0.0, 
 
 Culture=neutral, publicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
If you could help me I would appreiate it a lot. Thanks for your time
Can somebody give me a directly, up to know I am stuck with the Password, PasswordSalt arguments plus the hashing behavior.
Can someone tell me how I can achieve that? Thanks in advance, Joannès
"Method is only supported if the user name parameter matches the user name in the current Windows Identity."
I'm using Web Dev Express, maybe that's the problem?
Any chance you have code on implementing a custom role provider using AzMan roles with ADAM with Forms web based authentication? I referened the MSDN version for odbc, but the implementation seems very differnt than using roles with Azman/ADAM.
Thanks in advance,
Harry
I haven't worked with membership and Azman/ADAM as yet, sorry. It is something I have to do at some point in the future.
i've added an existing remote database in my machine.config file, and i've set it as the membership/role provider in the configuration tool. everything seems to work fine on the development server, but not on my live hosting server. any ideas why this might be so? i'm wondering if it's something to do with the 'type' attribute of the provider elements?
Finally I discovered this url and with it some great tips
I ran the wizard and entered the SQL server authentication username and password on the database.
I included the string of code for the config file relating to my new database
But if I test the provider in the asp.net tool I get this error.
Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.
I see that there is no additional user id or password repeated in the connectionstring but I'm guessing it doesn't need it. Although I have tried including it but I still get the same error.
What have I missed?
managed to impliment fine, by i get a cast error when using memebership.getuser()
thanks
i am using sql server data base in my app not sql express database .but when i run the app then aspnet.db data base automatically come .
so plzz tell me what can i do for it..
Hope that helps!
Can I use Asp.net Configuration tool for adding Roles and Users if I am using custome providers with a DB other than SQL Server say Ingres?
1. I have Sql Server installed and wants to operate with the database in Sql Server.
2. I tried to make custom membership provider and role provider by implementing sealed MembershipProvider and RoleProvider.
3.I have gone through the steps that you have mentioned in ur article.But I m geting the following error while I try to use security in ASP.Net Configuration.
"The method or operation is not implemented."
Please help me!!
You can email me @: p_meeru444@hotmail.com
Thank You!
I have a web page through this page when I try to add a new user then users created successfully but when try resetting their password then I am getting errors’
add New user successfully
public static void AddUser(ADUser adUser)
{
// Local variables
DirectoryEntry oDE = null;
DirectoryEntry oDENewUser = null;
DirectoryEntries oDEs = null;
try
{
oDE = GetDirectoryEntry(GetADPath(PROD, adUser.UserType));
// 1. Create user account
oDEs = oDE.Children;
oDENewUser = oDEs.Add("CN=" + adUser.UserName, "user");
// 2. Set properties
SetProperty(oDENewUser, "givenName", adUser.FirstName);
SetProperty(oDENewUser, "sn", adUser.LastName);
SetProperty(oDENewUser, "mail", adUser.Email);
SetProperty(oDENewUser, "sAMAccountName", adUser.UserName);
oDENewUser.CommitChanges();
/// 4. Enable account
EnableAccount(oDENewUser);
// 3. Set password
//SetPassword(oDENewUser, adUser.Password);
SetPassword1(oDENewUser.Path, adUser.Password);
oDENewUser.CommitChanges();
oDENewUser.Close();
oDE.Close();
}
catch (Exception ex)
{
throw ex;
}
}
I have try the following 2 SetPassword methods but getting error.
Method 1.
internal static void SetPassword1(string path, string userPassword)
{
//Local variables
DirectoryEntry usr = null;
try
{
usr = new DirectoryEntry();
usr.Path = path;
usr.AuthenticationType = AuthenticationTypes.Secure;
object ret = usr.Invoke("SetPassword", userPassword);
usr.CommitChanges();
usr.Close();
}
catch (Exception ex)
{
throw ex;
}
}
The exception raised (Error Code 80072035: The server is unwilling to process the request)
Method 2.
internal static void SetPassword(DirectoryEntry de, string userPassword)
{
//Local variables
//DirectoryEntry usr = null;
string quotePwd;
byte[] pwdBin;
try
{
quotePwd = String.Format(@"""{0}""", userPassword);
pwdBin = System.Text.Encoding.Unicode.GetBytes(quotePwd);
de.Properties["unicodePwd"].Value = pwdBin;
de.CommitChanges();
//usr.Close();
}
catch (Exception ex)
{
throw ex;
}
}
The exception raised ("Exception has been thrown by the target of an invocation.")
Is there an easy way to tell if there is a problem with changing a password?
Please reply me as soon as possible.
Thanks.