Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

ASP.net and GAC

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SP - 24 Oct 2005 02:51 GMT
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();
           
        }
Kevin Spencer - 24 Oct 2005 12:36 GMT
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?

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

> Hello there,
>
[quoted text clipped - 138 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.