locked
Experiencing "The type or namespace name ‘DirectoryServices’ does not exist in the namespace ‘System’ (are you missing an assembly reference?)" compilation error RRS feed

  • Question

  • I am just starting to implement a new user login authentication process wherein after prompting user for username & password, I hope to authenticate them againts our company Active Directory user data. Since I am just starting, I only have very few things done at this point which is how I wanted to work on this so that my development environment is still at its simplest state.

    I am using the following for development:

    • MS-Visual Studios Professional 2013 Version 12.0.30501.00 Update 2, and
    • MS .NET Framework Version 4.5.50938.

    Here are my project solution's current items:

    • Web.config:
    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
    
        <system.web>
          <compilation debug="true" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5" />
        </system.web>
    
    	<system.webServer>
    		<defaultDocument enabled="true">
    			<files>
    				<add value="Login.aspx" />
    			</files>
    		</defaultDocument>
    	</system.webServer>
    </configuration>
    


    • Web.Debug.config:
    <?xml version="1.0" encoding="utf-8"?>
    
    <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
    
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <!--
        In the example below, the "SetAttributes" transform will change the value of 
        "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
        finds an attribute "name" that has a value of "MyDB".
        
        <connectionStrings>
          <add name="MyDB" 
            connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
            xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
        </connectionStrings>
      -->
      <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
        <!--
          In the example below, the "Replace" transform will replace the entire 
          <customErrors> section of your web.config file.
          Note that because there is only one customErrors section under the 
          <system.web> node, there is no need to use the "xdt:Locator" attribute.
          
          <customErrors defaultRedirect="GenericError.htm"
            mode="RemoteOnly" xdt:Transform="Replace">
            <error statusCode="500" redirect="InternalError.htm"/>
          </customErrors>
        -->
      </system.web>
    </configuration>
    • Web.Assemblies.config:
    <?xml version="1.0"?>
    
    <configuration>
    
        <system.web>
          <compilation debug="false" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5" />
    
    		<assemblies>
    			<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral PublicKeyToken=b03f5f7f11d50a3a"/>
    		</assemblies>
    	</system.web>
    
    </configuration>
    

    • Login.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="loginForm" style="height: 562px; width: 399px; margin-left: 0px" title="Login Form">
        
        &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="loginPageLabel" runat="server" Font-Bold="True" Font-Names="Arial Black" Font-Size="Large" Text="Please Log In"></asp:Label>
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="loginUsernameLabel" runat="server" Text="Username:"></asp:Label>
    &nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="loginUserNameTextBox" runat="server" OnTextChanged="loginUserNameTextBox_TextChanged" Width="213px" Wrap="False" AutoPostBack="True" TabIndex="1"></asp:TextBox>
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            <asp:Label ID="loginPasswordLabel" runat="server" Text="Password:"></asp:Label>
            &nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="loginPasswordTextBox" runat="server" OnTextChanged="loginPasswordTextBox_TextChanged" Width="212px" Wrap="False" AutoPostBack="True" TabIndex="2"></asp:TextBox>
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:RadioButton ID="loginUAradioButton" runat="server" Font-Bold="True" OnCheckedChanged="loginUAradioButton_CheckedChanged" Text="TUPSS Associate" AutoPostBack="True" TabIndex="3" />
    &nbsp;&nbsp;
            <asp:RadioButton ID="loginAFradioButton" runat="server" Font-Bold="True" OnCheckedChanged="loginAFradioButton_CheckedChanged" Text="Area Franchisee" AutoPostBack="True" TabIndex="4" />
            <br />
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="loginSubmitButton" runat="server" Font-Bold="True" OnClick="loginSubmitButton_Click" Text="Log In" TabIndex="5" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="loginCancelButton" runat="server" Font-Bold="True" OnClick="loginCancelButton_Click" Text="Cancel" TabIndex="6" />
        
            <br />
            <br />
    &nbsp;&nbsp;
            <asp:Label ID="loginStatusInstructionLabel" runat="server" Text="Status/Instruction:"></asp:Label>
            <br />
    &nbsp;&nbsp;
            <asp:TextBox ID="loginStatusInstructionTextBox" runat="server" Height="230px" MaxLength="100" Rows="12" TextMode="MultiLine" Width="360px" EnableViewState="False" OnTextChanged="loginStatusInstructionTextBox_TextChanged" ReadOnly="True" TabIndex="-1"></asp:TextBox>
        
        </div>
        </form>
    </body>
    </html>
    

    • Login.aspx.cs:
    using System;
    using System.DirectoryServices; 
    
    public partial class Login : System.Web.UI.Page
    {
        private string uName;                // user-entered username
        private string pWord;                // user-entered password
        private int    loginLoadCycles;      // just keeping track of how many times Page_Load is called
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.loginUserNameTextBox.Text == String.Empty &&
                this.loginPasswordTextBox.Text == String.Empty &&
                this.loginUAradioButton.Checked == false &&
                this.loginAFradioButton.Checked == false)
                this.loginInit();
            this.setLoginVisibilityAndFocus();
            this.loginLoadCycles += 1;
        }
    
        private void loginInit()
        {
            this.uName = String.Empty;
            this.pWord = String.Empty;
            this.loginLoadCycles = 0;
        }
    
        private void setLoginVisibilityAndFocus()
        {
            // Decide on whether or not the Login submit & cancel buttons should be enabled or not
            if ( this.loginUserNameTextBox.Text == String.Empty ||
                (this.loginUAradioButton.Checked == false && this.loginAFradioButton.Checked == false) )
            {
                this.loginSubmitButton.Enabled = false;
                this.loginCancelButton.Enabled = false;
                this.loginStatusInstructionTextBox.Text = "Please specify if you are a TUPSS Associate or an Area Franchisee by checking either the 'TUPSS Associate' or 'Area Franchisee' checkbox.";
            }
            else
            {
                this.loginSubmitButton.Enabled = true;
                this.loginCancelButton.Enabled = true;
                if (this.loginPasswordTextBox.Text == String.Empty)
                    this.loginStatusInstructionTextBox.Text = "Now that you have entered your username & type, please enter your password.";
                else
                    this.loginStatusInstructionTextBox.Text = "When you are ready, please select either the Log In button to login, or the Cancel button to abort.";
            }
    
            if (this.loginUAradioButton.Checked == false && this.loginAFradioButton.Checked == false)
                this.SetFocus(this.loginUAradioButton);
            else if (this.loginUserNameTextBox.Text == String.Empty)
                this.SetFocus(this.loginUserNameTextBox);
            else if (this.loginPasswordTextBox.Text == String.Empty)
                this.SetFocus(this.loginPasswordTextBox);
            else
                this.SetFocus(this.loginSubmitButton);
        }
    
        protected void loginUserNameTextBox_TextChanged(object sender, EventArgs e)
        {
    
        }
    
        protected void loginPasswordTextBox_TextChanged(object sender, EventArgs e)
        {
            // For some reason, after specifying that the password entry box's textmode to 'Password' setting,
            // the UI's password textbox is emptied
            this.loginStatusInstructionTextBox.Text = "NOTICE:\nThis application is still under development.\n\n" +
                                                      "This is why the password you entered is visible. Once this portion of the application is ready, it will be masked.\n\n" +
                                                      "Also, still need to figure out why when changing this to Password entry mode to mask its entered data, password is getting reset.";
    
        }
    
        protected void loginSubmitButton_Click(object sender, EventArgs e)
        {
            this.loginLoadCycles = 0;
            this.uName = this.loginUserNameTextBox.Text;
            this.pWord = this.loginPasswordTextBox.Text;
            if (this.loginUAradioButton.Checked == true && this.loginAFradioButton.Checked == false)
            {
                this.loginLADPauthenticate('U');   // authenticate UPS Associates against UPS Corp's Active Directory
            }
            else if (this.loginUAradioButton.Checked == false && this.loginAFradioButton.Checked == true)
            {
                this.loginLADPauthenticate('A');   // authenticate Area Franchisees against UPS Store's iNet Active Directory
            }
            else
            {
                // set colors to show that this is an error instead of a status message or instruction
                this.loginStatusInstructionTextBox.Text = "ERROR: Cannot log in without specifying if you are an UPS Associate or an Area Franchisee!";
            }
        }
    
        protected void loginCancelButton_Click(object sender, EventArgs e)
        {
            this.loginStatusInstructionTextBox.Text = "You have selected to cancel from logging in...";
            // Still need to plan what to do when user cancels out of logging in. For now, just initialize class attributes
            this.loginInit();
        }
    
        protected void loginUAradioButton_CheckedChanged(object sender, EventArgs e)
        {
            String msg = String.Empty;
    
            if (this.loginUAradioButton.Checked == true)
            {
                this.loginAFradioButton.Checked = false;
                msg = "Thanks for specifying that you are a TUPSS Associate. ";
                if (this.loginUserNameTextBox.Text == String.Empty)
                    msg += "Now please specify your username.";
                else if (this.loginPasswordTextBox.Text == String.Empty)
                    msg += "Now please enter your password.";
            }
            this.loginStatusInstructionTextBox.Text = msg;
        }
        protected void loginAFradioButton_CheckedChanged(object sender, EventArgs e)
        {
            String msg = String.Empty;
    
            if (this.loginAFradioButton.Checked == true)
            {
                this.loginUAradioButton.Checked = false;
                msg = "Thanks for specifying that you are an Area Franchisee. ";
                if (this.loginUserNameTextBox.Text == String.Empty)
                    msg += "Now please specify your username.";
                else if (this.loginPasswordTextBox.Text == String.Empty)
                    msg += "Now please enter your password.";
            }
            this.loginStatusInstructionTextBox.Text = msg;
        }
    
        private void loginLADPauthenticate(char whichActiveDirectory)
        {
            String msg = "Authenticating user '" + this.uName + "' with password '" + this.pWord + "' against ";
    
            if (whichActiveDirectory == 'U')
                msg += "UPS Corp's Active Directory...";
            else if (whichActiveDirectory == 'A')
                msg += "The UPS  Store's Franchisee Active Directory...";
            msg += "\n\nNOTICE:\nThis is still under development.\n\nAt this point, this application is supposed to do something else now but is not yet ready.";
            this.loginStatusInstructionTextBox.Text = msg;
            this.loginStatusInstructionTextBox.AutoPostBack = true;
    
            // Authenticate using LDAP
            
        }
        protected void loginStatusInstructionTextBox_TextChanged(object sender, EventArgs e)
        {
    
        }
    }

    I confirmed that I have System.DirectoryServices.dll located in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\v4.0_4.0.0.0__b03f5f7f11d50a3a\ folder and that I as well as System have read as well as read&execute privileges not only to all folders in its path but also to the DLL file itself.

    I would appreciate any help in trying to resolve this compilation error so that I can proceed with implementing LDAP features for this endeavor.

    Thanks so much,

    hguico @ The UPS Store

    • Moved by Anne Jing Monday, June 23, 2014 7:20 AM
    Saturday, June 21, 2014 12:35 AM

Answers

  • Hi,

    For web application problem, please post your thread in ASP.NET forum.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Just Karl Tuesday, June 24, 2014 3:23 PM
    • Marked as answer by Just Karl Thursday, July 10, 2014 10:37 PM
    Monday, June 23, 2014 7:20 AM

All replies

  • Does it work if you set the Copy Local property to True on the assembly reference in your Project?

    Monday, June 23, 2014 6:03 AM
  • Hi,

    For web application problem, please post your thread in ASP.NET forum.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Just Karl Tuesday, June 24, 2014 3:23 PM
    • Marked as answer by Just Karl Thursday, July 10, 2014 10:37 PM
    Monday, June 23, 2014 7:20 AM