updating ActiveDirectoryMembershipProvider settings at runtime

P

Parag Mahajan

Hi,

I am using the membership provider class, "System.Web.Security.ActiveDirectoryMembershipProvider".
I am using Login Server control and attaching the already configured "ActiveDirectoryMembershipProvider" in the web.config file. But my restriction is that I do not want to give the "connectionUsername" and "connectionPassword" in the web.config file.

I want to update this 2 attributes at runtime in the Login1_LoggingIn event handler, so that the user will be able to authenticated with his login credentials only, provided the user inputs a valid & correct domain user name & password.

I see that when I set the MembershipProvider property of the Login1 server control, it picks up the settings only from the web.config file and not the runtime-updated values.

How could I achive this?

Below is the code snippet, where I am stucked..

_______________


ad = new ActiveDirectoryMembershipProvider();
NameValueCollection configNameValueCollection = new NameValueCollection();
string sDomainUserName = WebConfigurationManager.AppSettings["DomainName"] + "\\" + Login1.UserName;
// "DomainName" is one app setting which stores the actual domain name.
configNameValueCollection.Add("connectionUsername", sDomainUserName);
configNameValueCollection.Add("connectionPassword", Login1.Password);
configNameValueCollection.Add("attributeMapUsername", "sAMAccountName");
configNameValueCollection.Add("connectionStringName", "DomainConnectionString");

ad.Initialize("DomainADMembershipProvider", configNameValueCollection);
// Here "DomainADMembershipProvider" is the same name as specified in web.config file.
Login1.MembershipProvider = ad.Name;

_______________

Let me know if this is possible..
Thanks,
Parag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top