ASP.net and GAC 
November 19th, 2005, 10:06 PM
| | | |
Hello there,
I have a following peice of code which access AD.
When I place the code in ASP.net page it works fine.
but when I create a class and put the code in the class, and then
compile the class and register it in the GAC, and reference it in my
ASP.net project,and create a instance of the class and call the method
which holds the method, I get an error.
below is the code, does the security context change when the class is
being called?, I have set impersonisation to true in the web
application
Please suggest!
Thanks,
SP
public string itnMembersOf()
{
string tmp1 = "";
DirectoryEntry my_ent = new
DirectoryEntry("LDAP://immunetolerance.org/OU=testou1,OU=testou2,DC=immunetolerance,DC=org");
my_ent.Username = "test@immunetolerance.org";
my_ent.Password = "pass";
DirectorySearcher my_srch = new DirectorySearcher(my_ent);
my_srch.Filter = "(SAMAccountName=spai)";
SearchResult my_result = my_srch.FindOne () ;
DirectoryEntry my_ent1 = my_result.GetDirectoryEntry();
my_ent1.Username = "test@immunetolerance.org";
my_ent1.Password = "pass";
my_ent1.RefreshCache(new string[] {"tokenGroups"});
foreach (object groupSid in my_ent1.Properties["tokenGroups"])
{
byte[] sid = (byte[])groupSid;
try
{
DirectoryEntry groupEntry = new
DirectoryEntry(string.Format("LDAP://<sid={0}>",
ConvertToOctetString(sid)));
groupEntry.Username ="test@immunetolerance.org";
groupEntry.Password ="pass";
PropertyCollection propcoll = groupEntry.Properties;
string delimStr = ",";
char [] delimiter = delimStr.ToCharArray();
string[] atemp = null;
foreach(string key in propcoll.PropertyNames)
{
foreach(object values in propcoll[key])
{
if (key.ToLower() == "distinguishedname")
{
string temp;
temp = values.ToString();
if (temp.IndexOf("ImportedExchange") < 0)
{
atemp = temp.Split(delimiter);
tmp1 += atemp[0].Replace("CN=",",");
if (tmp1.StartsWith(","))
{
tmp1 = tmp1.Substring(1,tmp1.Length-2 );
}
}
}
}
}
}
catch(Exception ex)
{
TextBox1.Text = ex.Message ;
}
}
return tmp1;
public static string ConvertToOctetString(byte[] values)
{
return ConvertToOctetString(values,false,false);
}
public static string ConvertToOctetString(byte[] values, bool
isAddBackslash)
{
return ConvertToOctetString(values,isAddBackslash, false);
}
public static string ConvertToOctetString( byte[] values, bool
isAddBackslash, bool isUpperCase)
{
int iterator;
StringBuilder builder = new StringBuilder(values.Length * 2);
string slash;
if (isAddBackslash)
{
slash = "\\";
}
else
{
slash = string.Empty;
}
string formatCode;
if (isUpperCase)
{
formatCode = "X2";
}
else
{
formatCode = "x2";
}
for (iterator=0; iterator < values.Length; iterator++)
{
builder.Append(slash);
builder.Append(values[iterator].ToString(formatCode));
}
return builder.ToString();
} | 
November 19th, 2005, 10:06 PM
| | | | re: ASP.net and GAC
I have a car. What can you tell me about this car? You have an error. What
can I tell you about this error?
Not much. Could you describe the error, please? what is the type of
exception? What is the message? What does the stack trace in the exception
tell you about where the exception occurred?
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"SP" <spasp_net@hotmail.com> wrote in message
news:1130118694.860757.10950@f14g2000cwb.googlegro ups.com...[color=blue]
> Hello there,
>
> I have a following peice of code which access AD.
>
> When I place the code in ASP.net page it works fine.
>
> but when I create a class and put the code in the class, and then
> compile the class and register it in the GAC, and reference it in my
> ASP.net project,and create a instance of the class and call the method
> which holds the method, I get an error.
>
> below is the code, does the security context change when the class is
> being called?, I have set impersonisation to true in the web
> application
>
> Please suggest!
>
> Thanks,
> SP
>
> public string itnMembersOf()
> {
>
> string tmp1 = "";
>
> DirectoryEntry my_ent = new
> DirectoryEntry("LDAP://immunetolerance.org/OU=testou1,OU=testou2,DC=immunetolerance,DC=org");
>
> my_ent.Username = "test@immunetolerance.org";
> my_ent.Password = "pass";
>
> DirectorySearcher my_srch = new DirectorySearcher(my_ent);
> my_srch.Filter = "(SAMAccountName=spai)";
> SearchResult my_result = my_srch.FindOne () ;
>
> DirectoryEntry my_ent1 = my_result.GetDirectoryEntry();
> my_ent1.Username = "test@immunetolerance.org";
> my_ent1.Password = "pass";
> my_ent1.RefreshCache(new string[] {"tokenGroups"});
>
> foreach (object groupSid in my_ent1.Properties["tokenGroups"])
> {
> byte[] sid = (byte[])groupSid;
>
> try
> {
>
> DirectoryEntry groupEntry = new
> DirectoryEntry(string.Format("LDAP://<sid={0}>",
> ConvertToOctetString(sid)));
>
> groupEntry.Username ="test@immunetolerance.org";
> groupEntry.Password ="pass";
> PropertyCollection propcoll = groupEntry.Properties;
>
> string delimStr = ",";
> char [] delimiter = delimStr.ToCharArray();
> string[] atemp = null;
>
> foreach(string key in propcoll.PropertyNames)
> {
>
> foreach(object values in propcoll[key])
> {
>
> if (key.ToLower() == "distinguishedname")
> {
> string temp;
> temp = values.ToString();
>
> if (temp.IndexOf("ImportedExchange") < 0)
> {
> atemp = temp.Split(delimiter);
> tmp1 += atemp[0].Replace("CN=",",");
> if (tmp1.StartsWith(","))
> {
> tmp1 = tmp1.Substring(1,tmp1.Length-2 );
> }
> }
> }
> }
> }
>
>
> }
> catch(Exception ex)
> {
> TextBox1.Text = ex.Message ;
> }
>
> }
>
> return tmp1;
>
>
>
> public static string ConvertToOctetString(byte[] values)
> {
> return ConvertToOctetString(values,false,false);
> }
>
> public static string ConvertToOctetString(byte[] values, bool
> isAddBackslash)
> {
> return ConvertToOctetString(values,isAddBackslash, false);
> }
>
> public static string ConvertToOctetString( byte[] values, bool
> isAddBackslash, bool isUpperCase)
> {
>
> int iterator;
> StringBuilder builder = new StringBuilder(values.Length * 2);
>
> string slash;
>
> if (isAddBackslash)
> {
> slash = "\\";
> }
> else
> {
> slash = string.Empty;
> }
>
> string formatCode;
>
> if (isUpperCase)
> {
> formatCode = "X2";
> }
> else
> {
> formatCode = "x2";
> }
>
> for (iterator=0; iterator < values.Length; iterator++)
> {
> builder.Append(slash);
> builder.Append(values[iterator].ToString(formatCode));
> }
>
>
>
> return builder.ToString();
>
> }
>[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|