c# - Check if User/Email exists in AD -
i have form in page user informs email or user name other user. in submit event, need check information exists in active directory. how make check?? i'm clear?
my page
<asp:label id="lbluseradd" runat="server" font-bold="true" text="add user - (email or user name)"></asp:label> <br /> <asp:textbox id="txtuseradd" runat="server" height="17px" width="150px"></asp:textbox> <asp:label id="lblerror" runat="server" class="control-label" for="inputerror" visible="false">input error</asp:label> <asp:label id="lblsuccess" runat="server" class="control-label" for="inputsuccess" visible="false">input success</asp:label> <asp:button id="btnadduser" class="btn" runat="server" font-bold="true" text="add user" onclick="btnsenduser_onclick" /> <br /> <table id="tblusers" class="table table-bordered"> <asp:label id="lbluser" runat="server" visible="false"></asp:label> </table> my .cs
protected void btnsenduser_onclick(object sender, eventargs e) { principalcontext addomain = new principalcontext(contexttype.domain, "x.com", "amsndruser", "x"); lbluser.visible = true; lbluser.text = txtuseradd.text; if (txtuseradd.text != "email ad" || txtuseradd.text != "user name ad" || txtuseradd.text != "user ad") { lblerror.visible = true; } else { lblsuccess.visible = true; } }
i create solution this.
protected void btnsenduser_onclick(object sender, eventargs e) { string loginfo = txtuseradd.text; string logininfo = txtuseradd.text; principalcontext insprincipalcontext = new principalcontext(contexttype.domain, "x.com", "amsndruser", "xxx"); userprincipal insuserprincipal = userprincipal.findbyidentity(insprincipalcontext, logininfo); if (insuserprincipal == null) { lblerror.visible = true; } else { lblsuccess.visible = true; lbluser.visible = true; lbluser.text = txtuseradd.text; } }
Comments
Post a Comment