Checking if user is in grouphttp://forums.asp.net/t/1013982.aspx/1?Checking+if+user+is+in+groupThu, 31 Aug 2006 17:20:03 -040010139821359281http://forums.asp.net/p/1013982/1359281.aspx/1?Checking+if+user+is+in+groupChecking if user is in group <p><span>Im trying to check to see if a user is in a group and if so i want to display some imnofrmation if not i want to hide everything.&nbsp; So&nbsp;i set this up to see if i can check if a user is in say true&nbsp;if not false but i am getting the following error.&nbsp; Can anyone help me out on this please.&nbsp; </span></p> <p><span>&nbsp;</p> <h1>Server Error in '/WebSite5' Application. <hr width="100%" color="silver" size="1"> </h1> <h2><i>An operations error occurred.<br> </i></h2> </span><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><b>Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br> <br> <b>Exception Details: </b>System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.<br> <br> <br> <b>Source Error:</b> <br> <br> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td><pre class="prettyprint"><pre>Line 22: DirectorySearcher adsSearch = new DirectorySearcher(adsRoot);</pre> Line 23: strUser = Context.User.Identity.Name.ToString(); Line 24: SearchResult sresult = adsSearch.FindOne(); Line 25: if (sresult == null) Line 26: Response.Write(&quot;False&quot;); <pre></pre></pre></TD></TR></TBODY></TABLE><BR><B><FONT face=Verdana>Source File: </FONT></B>c:\ProgrammingFiles\WebSite5\test.aspx.cs<B><FONT face=Verdana> &nbsp;&nbsp; Line: </FONT></B>24 <BR><BR><B><FONT face=Verdana>Stack Trace:</FONT></B> <BR><BR> <TABLE width="100%" bgColor=#ffffcc> <TBODY> <TR> <TD><pre class="prettyprint"><PRE>[DirectoryServicesCOMException (0x80072020): An operations error occurred. ] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +634 System.DirectoryServices.DirectoryEntry.Bind() +36 System.DirectoryServices.DirectoryEntry.get_AdsObject() +31 System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +73 System.DirectoryServices.DirectorySearcher.FindOne() +42 test.Page_Load(Object sender, EventArgs e) in c:\ProgrammingFiles\WebSite5\test.aspx.cs:24 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45 System.Web.UI.Control.OnLoad(EventArgs e) +80 System.Web.UI.Control.LoadRecursive() +49 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745 </PRE></pre></TD></TR></TBODY></TABLE> <P></FONT>&nbsp;</P><pre class="prettyprint"><SPAN class=kwd>using</SPAN> System; <SPAN class=kwd>using</SPAN> System.Data; <SPAN class=kwd>using</SPAN> System.Configuration; <SPAN class=kwd>using</SPAN> System.Collections; <SPAN class=kwd>using</SPAN> System.Web; <SPAN class=kwd>using</SPAN> System.Web.Security; <SPAN class=kwd>using</SPAN> System.Web.UI; <SPAN class=kwd>using</SPAN> System.Web.UI.WebControls; <SPAN class=kwd>using</SPAN> System.Web.UI.WebControls.WebParts; <SPAN class=kwd>using</SPAN> System.Web.UI.HtmlControls; <SPAN class=kwd>using</SPAN> System.DirectoryServices; <SPAN class=kwd>public</SPAN> partial <SPAN class=kwd>class</SPAN> test : System.Web.UI.Page { <SPAN class=kwd>protected void</SPAN> Page_Load(<SPAN class=kwd>object</SPAN> sender, System.EventArgs e) { <SPAN class=kwd>string</SPAN> strUser; DirectoryEntry adsRoot = <SPAN class=kwd>new</SPAN> DirectoryEntry(<SPAN class=st>"LDAP:<SPAN class=cmt>//server/dc=abc,dc=com,ou=app-ckmaint");</SPAN> DirectorySearcher adsSearch = new DirectorySearcher(adsRoot); strUser = Context.User.Identity.Name.ToString(); SearchResult sresult = adsSearch.FindOne(); if (sresult == null) Response.Write("</SPAN>False<SPAN class=st>"); else Response.Write("</SPAN>True"); } }</pre>&nbsp;</td> </tr> </tbody> </table> </font> 2006-08-02T21:57:03-04:001360078http://forums.asp.net/p/1013982/1360078.aspx/1?Re+Checking+if+user+is+in+groupRe: Checking if user is in group <p>i got it to work on localhost by changing the order around on the ldap connection but when moving it over to production i now get a similar error just on the Interop instead of DirectoryServices.&nbsp; Any ideas?</p> <p>&nbsp;</p> <p><span></p> <h1>Server Error in '/' Application. <hr width="100%" color="silver" size="1"> </h1> <h2><i>An operations error occurred.<br> </i></h2> <p></span><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><b>Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br> <br> <b>Exception Details: </b>System.Runtime.InteropServices.COMException: An operations error occurred.<br> <br> <br> <b>Source Error:</b> <br> <br> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td><pre class="prettyprint"><pre>Line 23: strUser = Context.User.Identity.Name.ToString();</pre> Line 24: //adsSearch.Filter = &quot;(member=&quot;&#43;strUser&#43;&quot;)&quot;; Line 25: SearchResult sresult = adsSearch.FindOne(); Line 26: if (sresult == null) Line 27: Response.Write(&quot;False&quot;); <pre></pre></pre></TD></TR></TBODY></TABLE><BR><B><FONT face=Verdana>Source File: </FONT></B>d:\intranet\test.aspx.cs<B><FONT face=Verdana> &nbsp;&nbsp; Line: </FONT></B>25 <BR><BR><B><FONT face=Verdana>Stack Trace:</FONT></B> <BR><BR> <TABLE width="100%" bgColor=#ffffcc> <TBODY> <TR> <TD><pre class="prettyprint"><PRE>[COMException (0x80072020): An operations error occurred. ] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +610 System.DirectoryServices.DirectoryEntry.Bind() +36 System.DirectoryServices.DirectoryEntry.get_AdsObject() +31 System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +73 System.DirectoryServices.DirectorySearcher.FindOne() +42 test.Page_Load(Object sender, EventArgs e) in d:\intranet\test.aspx.cs:25 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061 </PRE></pre></td> </tr> </tbody> </table> </font></p> 2006-08-03T15:59:02-04:001360120http://forums.asp.net/p/1013982/1360120.aspx/1?Re+Checking+if+user+is+in+groupRe: Checking if user is in group I will let Joe continue to help you on the other forum where you posted this.<br> 2006-08-03T16:30:15-04:001384612http://forums.asp.net/p/1013982/1384612.aspx/1?Re+Checking+if+user+is+in+groupRe: Checking if user is in group <p>Can you please paste the link to the forum where this was answered?</p> <p>&nbsp;</p> <p>Thank you :)&nbsp;</p> 2006-08-30T08:30:31-04:001386268http://forums.asp.net/p/1013982/1386268.aspx/1?Re+Checking+if+user+is+in+groupRe: Checking if user is in group <p>it was a simple one line peice of code.</p> <p><font color="#0000ff" size="2">bool</font><font size="2"> access = Context.User.IsInRole(</font><font color="#800000" size="2">@&quot;DOMAIN\group&quot;</font><font size="2">);</font></p> <p><font size="2">this will return true or false depending on if the user your checking against is in the group or not</font></p> 2006-08-31T17:20:03-04:00