Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:23:24+00:00 2026-05-25T19:23:24+00:00

The following code works fine in Visual Studio Development enviroment on my local machine.

  • 0

The following code works fine in Visual Studio Development enviroment on my local machine. However when I move the files to a Windows 2008 R2 IIS 7.5 machine I get the following error:

[DirectoryServicesCOMException (0x80072020): An operations error
occurred. ] _Default.GetFullName(String strLoginName, String&
STR_FIRST_NAME, String& STR_LAST_NAME, String& STR_DISPLAY_NAME,
String& STR_MAIL, String& STR_OFFICE_PHONE, String& STR_ADDRESS) in
c:\AuthTest\Default.aspx.cs:87 _Default.Page_Load(Object sender,
EventArgs e) in c:\AuthTest\Default.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) +25 System.Web.UI.Control.LoadRecursive()
+71 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3064

I have Windows Authentication enabled on IIS so I’m not sure if I’m missing something else. Both my local machine and the web server are in the same domain.

Here is my code:

using System;
using System.DirectoryServices;
using System.Web.Hosting;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Gets the extracted User Name using a method.
        string strUserID = ExtractUserName(User.Identity.Name.ToString());

        string STR_FIRST_NAME;
        string STR_LAST_NAME;
        string STR_DISPLAY_NAME;
        string STR_MAIL;
        string STR_OFFICE_PHONE;
        string STR_ADDRESS;


        GetFullName(strUserID, out STR_FIRST_NAME, out STR_LAST_NAME, out STR_DISPLAY_NAME, 
            out STR_MAIL, out STR_OFFICE_PHONE, out STR_ADDRESS);

        lblHello.Text = "Your User ID is: " + strUserID;
        TextBox1.Text = 
            "Your name is: " + STR_FIRST_NAME + " " + STR_LAST_NAME + Environment.NewLine +
            "Display Name: " + STR_DISPLAY_NAME + Environment.NewLine + 
            "Email address: " + STR_MAIL + Environment.NewLine +
            "Office Phone: " + STR_OFFICE_PHONE + Environment.NewLine +
            "Address: " + STR_ADDRESS;
    }

        //Retrives User Name from DomainName\\UserName 
        private static string ExtractUserName(string path) 
        { 
            string[] userPath = path.Split(new char[] { '\\' }); 
            return userPath[userPath.Length - 1]; 
        }

        public static string GetFullName(string strLoginName, 
            out string STR_FIRST_NAME, 
            out string STR_LAST_NAME, 
            out string STR_DISPLAY_NAME, 
            out string STR_MAIL, 
            out string STR_OFFICE_PHONE, 
            out string STR_ADDRESS)
        {
            string userName = ExtractUserName(strLoginName);

            SearchResult result = null;

            using (HostingEnvironment.Impersonate())
            {
                DirectorySearcher search = new DirectorySearcher();
                search.Filter = String.Format("(SAMAccountName={0})", userName);
                search.PropertiesToLoad.Add("cn");
                STR_FIRST_NAME = "";
                STR_LAST_NAME = "";
                STR_DISPLAY_NAME = "";
                STR_MAIL = "";
                STR_OFFICE_PHONE = "";
                STR_ADDRESS = "";

                try
                {
                    result = search.FindOne();

                    foreach (System.Collections.DictionaryEntry direntry in result.Properties)
                    {
                        STR_FIRST_NAME = result.GetDirectoryEntry().Properties["givenName"].Value.ToString();
                        STR_LAST_NAME = result.GetDirectoryEntry().Properties["SN"].Value.ToString();
                        STR_DISPLAY_NAME = result.GetDirectoryEntry().Properties["DisplayName"].Value.ToString();
                        STR_MAIL = result.GetDirectoryEntry().Properties["mail"].Value.ToString();
                        STR_OFFICE_PHONE = result.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();
                        STR_ADDRESS = result.GetDirectoryEntry().Properties["streetAddress"].Value.ToString();
                    }
                    return null;
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
}

Again everything works fine on my local machine in the VS Testing enviroment. I’m probably missing some kind of configuration in IIS?

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:23:25+00:00Added an answer on May 25, 2026 at 7:23 pm

    First thing would be to check that the IIS application pool identity has the correct permissions to AD.

    Also as a side note here is something to read regarding your catch { throw ex}

    http://www.tkachenko.com/blog/archives/000352.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works fine for Visual C++ 2008. However, when comes to Visual
I have the following code which works fine. However, I only want to return
The following code works on Visual Studio 2005, but gives me a compiler error
I've found that the following code doesn't compile in Visual Studio 2010 (but works
I am wondering why the following contrived example code works perfectly fine in Visual
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code works fine #define open { #define close } #include<stdio.h> #define int
The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
At the moment I have the following code which works fine. label = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.