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. So i set this up to see if i can check if a user is in say true if not false but i am getting the following error. Can
anyone help me out on this please.
Server Error in '/WebSite5' Application.
An operations error occurred.
Description:
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.
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
Source Error:
Line 22: DirectorySearcher adsSearch = new DirectorySearcher(adsRoot);
Line 23: strUser = Context.User.Identity.Name.ToString();
Line 24: SearchResult sresult = adsSearch.FindOne();
Line 25: if (sresult == null)
Line 26: Response.Write("False");
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.DirectoryServices;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
string strUser;
DirectoryEntry adsRoot = new DirectoryEntry("LDAP://server/dc=abc,dc=com,ou=app-ckmaint");
DirectorySearcher adsSearch = new DirectorySearcher(adsRoot);
strUser = Context.User.Identity.Name.ToString();
SearchResult sresult = adsSearch.FindOne();
if (sresult == null)
Response.Write("False");
else
Response.Write("True");
}
}
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. Any ideas?
Server Error in '/' Application.
An operations error occurred.
Description:
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.
Exception Details: System.Runtime.InteropServices.COMException: An operations error occurred.
Source Error:
Line 23: strUser = Context.User.Identity.Name.ToString();
Line 24: //adsSearch.Filter = "(member="+strUser+")";
Line 25: SearchResult sresult = adsSearch.FindOne();
Line 26: if (sresult == null)
Line 27: Response.Write("False");
jgurgen
Participant
756 Points
254 Posts
Checking if user is in group
Aug 02, 2006 09:57 PM|LINK
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. So i set this up to see if i can check if a user is in say true if not false but i am getting the following error. Can anyone help me out on this please.
Server Error in '/WebSite5' Application.
An operations error occurred.
Description: 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.Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
Source Error:
Source File: c:\ProgrammingFiles\WebSite5\test.aspx.cs Line: 24
Stack Trace:
jgurgen
Participant
756 Points
254 Posts
Re: Checking if user is in group
Aug 03, 2006 03:59 PM|LINK
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. Any ideas?
Server Error in '/' Application.
An operations error occurred.
Description: 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.
Exception Details: System.Runtime.InteropServices.COMException: An operations error occurred.
Source Error:
Source File: d:\intranet\test.aspx.cs Line: 25
Stack Trace:
dunnry
Star
9098 Points
1806 Posts
Re: Checking if user is in group
Aug 03, 2006 04:30 PM|LINK
Weblog
The Book
LDAP Programming Help
Svein_Erik
Member
350 Points
70 Posts
Re: Checking if user is in group
Aug 30, 2006 08:30 AM|LINK
Can you please paste the link to the forum where this was answered?
Thank you :)
jgurgen
Participant
756 Points
254 Posts
Re: Checking if user is in group
Aug 31, 2006 05:20 PM|LINK
it was a simple one line peice of code.
bool access = Context.User.IsInRole(@"DOMAIN\group");
this will return true or false depending on if the user your checking against is in the group or not