"13.in和exist与in区别 怎么使用 "

When submitting valid credentials to Active Directory via a ASP.NET web form, the following error message is returned: "The specified directory service attribute or value does not exist."
Code for LDAP Authentication:
using System.T
using System.C
using System.DirectoryS
namespace FormsAuth
public class LdapAuthentication
private string _
private string _filterA
public LdapAuthentication(string path)
public bool IsAuthenticated(string domain, string username, string pwd)
string domainAndUsername = "CBHC" + @"\" +
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeO
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
//Update the new path to the user in the directory.
_path = result.P
_filterAttribute = (string)result.Properties["cn"][0];
catch (Exception ex)
throw new Exception("Error authenticating user. " + ex.Message);
public string GetGroups()
DirectorySearcher search = new DirectorySearcher(_path);
search.Filter = "(cn=" + _filterAttribute + ")";
search.PropertiesToLoad.Add("memberOf");
StringBuilder groupNames = new StringBuilder();
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].C
int equalsIndex, commaI
for (int propertyCounter = 0; propertyCounter & propertyC propertyCounter++)
dn = (string)result.Properties["memberOf"][propertyCounter];
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
groupNames.Append("|");
catch (Exception ex)
throw new Exception("Error obtaining group names. " + ex.Message);
return groupNames.ToString();
Code on login page:
&script runat=server&
void Login_Click(object sender, EventArgs e)
string adPath = "LDAP://server/DC=domain,DC=loc"; //Path to your LDAP directory server
LdapAuthentication adAuth = new LdapAuthentication(adPath);
if(true == adAuth.IsAuthenticated("CBHC",txtUsername.Text, txtPassword.Text))
string groups = adAuth.GetGroups();
//Create the ticket, and add the groups.
bool isCookiePersistent = chkPersist.C
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
txtUsername.Text,DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);
//Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//Create a cookie, and then add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
if(true == isCookiePersistent)
authCookie.Expires = authTicket.E
//Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
//You can redirect now.
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false));
errorLabel.Text = "Authentication did not succeed. Check user name and password.";
catch(Exception ex)
errorLabel.Text = "Error authenticating. " + ex.M
Authentication settings on Web.config for form on IIS:
&authentication mode="Windows"&
&forms loginUrl="logon.aspx" name="adAuthCookie" timeout="10" path="/" /&
&/authentication&
&authorization&
&deny users="?" /&
&allow users="*" /&
&/authorization&
&identity impersonate="true" /&
Word of note: This does not occur when running the site in D in that situation, it authenticates perfectly and moves on to the Default page. It only occurs when contacting the page live on the IIS server.
解决方案 I've hit an issue like this once. It may be because you can't retrieve LDAP NativeObject property for authentication. If the exception is thrown right after the object obj = entry.NativeO call, check if user has permissions on the domain.
Either debug through your code to see if it is indeed the NativeObject binding that is failing. Or Put a try/catch block around the binding in your IsAuthenticated() function like below. You should see the custom error thrown if it's caused by the issue I'm describing.
//Bind to the native AdsObject to force authentication.
Object obj = entry.NativeO
catch (System.Runtime.InteropServices.COMException e)
if (e.ErrorCode == -) // - - The specified directory service attribute or value does not exist.
throw new Exception("Can't retrieve LDAP NativeObject property");
本文地址: &
当通过ASP.NET Web窗体提交有效凭证到Active Directory,将返回以下错误信息:“指定的目录服务属性或值不存在”
code LDAP验证:
使用System.T
System.Collections中使用;
使用System.DirectoryServices中;
命名空间FormsAuth
公共类LdapAuthentication
私人字符串_
私人字符串_filterA
公共LdapAuthentication(字符串路径)
_path =路径;
公共BOOL IsAuthenticated(字符串域名,用户名字符串,字符串PWD)
字符串domainAndUsername =“CBHC”+ @“\”+用户名;
的DirectoryEntry条目=新的DirectoryEntry(_path,domainAndUsername,PWD);
//绑定本机AdsObject强制认证。
obj对象= entry.NativeO
DirectorySearcher从搜索=新DirectorySearcher从(输入);
search.Filter =“(SAM帐户名=”+用户名+“)”;
search.PropertiesToLoad.Add(“CN”);
信息搜索结果的结果= search.FindOne();
如果(空==结果)
//更新的新路径,在目录中的用户。
_path = result.P
_filterAttribute =(字符串)result.Properties [“CN”] [0];
赶上(例外前)
抛出新的异常(+ ex.Message“错误验证用户。”);
公共字符串GetGroups()
DirectorySearcher从搜索=新DirectorySearcher从(_path);
search.Filter =“(CN =”+ _filterAttribute +“)”;
search.PropertiesToLoad.Add(“成员”);
StringBuilder的组名=新的StringBuilder();
信息搜索结果的结果= search.FindOne();
INT propertyCount = result.Properties [“成员”]计数。
INT equalsIndex,commaI
对于(INT propertyCounter = 0; propertyCounter< propertyC propertyCounter ++)
DN =(字符串)result.Properties [“成员”] [propertyCounter]
equalsIndex = dn.IndexOf(“=”,1);
commaIndex = dn.IndexOf(“,”,1);
如果(-1 == equalsIndex)
groupNames.Append(dn.Substring((equalsIndex + 1),(commaIndex
equalsIndex) -
groupNames.Append(“|”);
赶上(例外前)
抛出新的异常(“错误获得组名。”+ ex.Message);
返回groupNames.ToString();
在登录页code:
<脚本RUNAT =服务器>
无效Login_Click(对象发件人,EventArgs的)
字符串adPath =“LDAP://服务器/ DC =域,DC = LOC”; //路径,您的LDAP目录服务器
LdapAuthentication adAuth =新LdapAuthentication(adPath);
如果(真== adAuth.IsAuthenticated(“CBHC”,txtUsername.Text,txtPassword.Text))
串组= adAuth.GetGroups();
//创建了票,并添加组。
布尔isCookiePersistent = chkPersist.C
的FormsAuthenticationTicket authTicket =新的FormsAuthenticationTicket(1,
txtUsername.Text,DateTime.Now,DateTime.Now.AddMinutes(60),isCookiePersistent,团体);
//加密票。
字符串的encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//创建的cookie,然后将加密票证添加到cookie数据。
的HttpCookie authCookie =新的HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket中);
如果(真正的== isCookiePersistent)
authCookie.Expires = authTicket.E
//饼干添加到即将卸任的Cookies集合。
Response.Cookies.Add(authCookie);
//现在可以重定向。
的Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text,FALSE));
errorLabel.Text =“验证未成功确认用户名和密码。”
赶上(例外前)
errorLabel.Text =“错误认证。”+ ex.M
< / SCRIPT>
有关IIS形式的Web.config身份验证设置:
<身份验证模式=“窗口”>
<形式loginUrl =“logon.aspx”NAME =“adAuthCookie”超时=“10”路径=“/”/>
< /认证>
<授权>
<拒绝用户=“?” />
<让用户=“*”/>
< /授权>
<身份冒充=“真”/>
值得注意的字:运行该网站在调试时,这不会发生;在这种情况下,它所验证完美并移动到默认页面。它只有在活页的IIS服务器上的接触发生。
解决方案 我已经打了一个这样的问题一次。这可能是因为你无法检索LDAP
NativeObject 属性进行身份验证。如果异常的 obj对象= entry.NativeObject后立即抛出。呼叫,检查用户对域权限
通过您的code无论是调试,看它是否确实是NativeObject绑定失败。或者将一个try / catch块周围像下面的IsAuthenticated()函数的结合。您应该看到自定义错误抛出,如果它引起我所描述的问题。
{//绑定到本地AdsObject强制认证。
obj对象= entry.NativeO
赶上(System.Runtime.InteropServices.COMException E)
如果(e.Error code == -)// -
- 指定的目录服务属性或值不存在。
抛出新的异常(“无法检索LDAP NativeObject财产”);
本文地址: &
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
(window.slotbydup = window.slotbydup || []).push({
id: '5828425',
container: s,
size: '300,250',
display: 'inlay-fix'I am new to android development, and I have been using the command line tools to create an android project.
I followed all the instructions given in the .
However, they are focused more on IDE users.
When I tried extending my MainActivity class from ActionBarActivity instead of just Activity, it threw the following error.
error: package android.support.v7.app does not exist
It was complaining about this import statement.
import android.support.v7.app.ActionBarA
I made sure to visit the SDK manager, and it says Android Support Library is installed.
I am truly stumped on this one, and I would really appreciate any help you guys could give me.
This might help:
解决方案 Your project is missing the support library from the SDK.
If you have no installed them, just right click on the project > Android Tools > Install support library.
Then, just import into workspace, as an Android project, android-support-v7-appcompat, located into ${android-sdk-path}/extras/android/support/v7
And finally, right click in the Android project > Properties > Android Tab. Push the Add button and add the support project "android-support-v7-appcompat" as dependency.
Clean your project and the must compile and work properly.
本文地址: &
我是新android开发,我一直在使用命令行工具来创建一个Android项目。我跟所有的Android开发者在
解决方案 您的项目缺少从SDK的支持库。
如果你没有安装的话,只需右键单击项目>安卓工具>安装支持库。
然后,只需导入到工作区中,作为一个Android项目,Android的支持-V7-appcompat,坐落在$ {Android的SDK路径} /演员/安卓/支持/ V7
最后,单击鼠标右键,在Android项目>属性> Android的标签。按Add按钮,添加支持项目“Android的支持-V7-appcompat”的依赖。
清理项目和必须编译和正常工作。
本文地址: &
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
(window.slotbydup = window.slotbydup || []).push({
id: '5828425',
container: s,
size: '300,250',
display: 'inlay-fix'U盘做开机密钥_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&100W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
U盘做开机密钥
&&U盘做开机密钥
你可能喜欢 上传我的文档
 上传文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
God the Known and God the Unknown(已知的上帝和未知的上帝)
下载积分:3000
内容提示:God the Known and God the Unknown(已知的上帝和未知的上帝)
文档格式:PDF|
浏览次数:0|
上传日期: 20:32:52|
文档星级:
全文阅读已结束,如果下载本文需要使用
 3000 积分
下载此文档
该用户还上传了这些文档
God the Known and God the Unknown(已知的上帝和未
关注微信公众号

我要回帖

更多关于 exist与in 的文章

 

随机推荐