我尝试使用ASP.Net的MembershipProvider仅授予某些用户访问权限。这由ADAM实例备份。
我使用了一些运行良好的测试代码:
public static DataTable getADValuesByParameter(string strFilter, string strLDAPUser, string strLDAPPath, string strLDAPPWD, string strLDAPProperties)
{
DataTable functionReturnValue = default(DataTable);
string[] arrLDAP = null;
DirectoryEntry rootEntry = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher();
SearchResultCollection results = default(SearchResultCollection);
DataTable dtExchangeUserData = new DataTable();
arrLDAP = strLDAPProperties.Split(new char[] { ',' });
rootEntry.Path = strLDAPPath;
rootEntry.Username = strLDAPUser;
rootEntry.Password = strLDAPPWD;
rootEntry.AuthenticationType = AuthenticationTypes.Secure;
searcher.SearchRoot = rootEntry;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = strFilter;
searcher.PropertiesToLoad.AddRange(arrLDAP);
//var value = rootEntry.NativeObject;
results = searcher.FindAll();
Int16 si = default(Int16);
foreach (SearchResult result in results)
{
si = 0;
object[] arrKeyValue = new object[result.Properties.Count - 1];
// -2 weil property "adspath" nicht dazu gehört, und .count -1 weil 0 basierendes array
if ((result != null))
{
System.Collections.IEnumerator myEnumerator = arrLDAP.GetEnumerator();
while (myEnumerator.MoveNext())
{
foreach (string Key in result.Properties.PropertyNames)
{
if (Key != "adspath")
{
if (Key.Equals(((string)myEnumerator.Current).ToLower()))
{
if (dtExchangeUserData.Columns[Key] == null)
dtExchangeUserData.Columns.Add(Key);
if (Key.Equals("objectguid"))
{
arrKeyValue[si] = new Guid(((byte[])result.Properties[Key][0]));
}
else
{
arrKeyValue[si] = result.Properties[Key][0].ToString();
}
si++;
}
}
}
}
if (arrKeyValue.Length > 0)
dtExchangeUserData.Rows.Add(arrKeyValue);
}
}
functionReturnValue = dtExchangeUserData;
dtExchangeUserData.Dispose();
rootEntry.Close();
rootEntry.Dispose();
return functionReturnValue;
}
在这里,我手动查询ADAM。尽管代码编写得很糟糕,但它仍然有效。请注意我如何使用“AuthenticationTypes.Secure”。
现在,当我尝试使用ActiveDirectoryMembershipProvider做同样的事情(相同的connectionPath,用户名,密码等)时,它给了我(大致翻译自德语):
ConfigurationErrorsException:不能 建立安全连接 SSL
当我致电
时会发生这种情况Membership.ValidateUser()
以下是Web.config文件中的相关部分:
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://server.com/OU=users,DC=test,DC=adam"/>
</connectionStrings>
<authentication mode="Forms" >
<forms loginUrl="~/Login.aspx/Test/" timeout="2880" />
</authentication>
<authorization>
<deny users ="?" />
</authorization>
<!--<identity impersonate="true" />-->
<trust level="Full" />
<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="[domain]\[user]"
connectionPassword="[password]"
connectionProtection="Secure"
enableSearchMethods="true"
/>
</providers>
</membership>
我是否使用模仿并不重要(说实话,我真的不知道它是做什么的)。信任级别也不会改变任何东西。
当我使用connectionProtection =“None”时,它会给我(再次翻译)“用户名或密码错误”。当我在手动示例中使用“AuthenticationTypes.None”时出现相同的错误。
我做错了什么?
感谢您的时间......