Connecting Tech Pros Worldwide Help | Site Map

ASP.net and GAC

  #1  
Old November 19th, 2005, 10:06 PM
SP
Guest
 
Posts: n/a
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();

}

  #2  
Old November 19th, 2005, 10:06 PM
Kevin Spencer
Guest
 
Posts: n/a

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]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
Cannot find DLL in 'Temp asp.net files' directory, error BC2017 Don answers 0 November 19th, 2005 10:51 PM
ASP .NET Compiler Error Message: CS1595 - IIS related problem??? abh1508 answers 1 November 19th, 2005 09:05 PM
Problem with 'header' user control in copied asp.net project Lauchlan M answers 1 November 18th, 2005 05:29 AM
Too many assemblies asp.net Lance Barger answers 7 November 17th, 2005 07:51 PM