Click here to Skip to main content
15,896,448 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: When Rebuild this website warining this error ? Pin
Member 245846712-Sep-19 22:14
Member 245846712-Sep-19 22:14 
GeneralRe: When Rebuild this website warining this error ? Pin
Richard MacCutchan12-Sep-19 22:21
mveRichard MacCutchan12-Sep-19 22:21 
GeneralRe: When Rebuild this website warining this error ? Pin
Member 245846715-Sep-19 15:22
Member 245846715-Sep-19 15:22 
QuestionHow solve this error "ModuleNotFoundError: No module named 'requests' " by using pycharm Pin
thilipr11-Sep-19 2:38
thilipr11-Sep-19 2:38 
SuggestionRe: How solve this error "ModuleNotFoundError: No module named 'requests' " by using pycharm Pin
Richard Deeming11-Sep-19 23:39
mveRichard Deeming11-Sep-19 23:39 
AnswerRe: How solve this error "ModuleNotFoundError: No module named 'requests' " by using pycharm Pin
Richard MacCutchan12-Sep-19 0:19
mveRichard MacCutchan12-Sep-19 0:19 
QuestionRazor Pages Inconsistent Behaviour Pin
Mycroft Holmes7-Sep-19 13:49
professionalMycroft Holmes7-Sep-19 13:49 
AnswerRe: Razor Pages Inconsistent Behaviour - Resolved Pin
Mycroft Holmes7-Sep-19 13:51
professionalMycroft Holmes7-Sep-19 13:51 
QuestionWhen I have deployed My web application In IIS I am getting some extra words Pin
Nigam,Ashish30-Aug-19 2:40
Nigam,Ashish30-Aug-19 2:40 
AnswerRe: When I have deployed My web application In IIS I am getting some extra words Pin
Richard Deeming30-Aug-19 3:16
mveRichard Deeming30-Aug-19 3:16 
Questionhen I have deploy My web application In IIS I am getting some extra words Pin
Nigam,Ashish30-Aug-19 2:35
Nigam,Ashish30-Aug-19 2:35 
QuestionError bind data to html datatable with WebMethod and JavaScript (No data available in table) Pin
BERTHA Nelson26-Aug-19 17:39
BERTHA Nelson26-Aug-19 17:39 
AnswerRe: Error bind data to html datatable with WebMethod and JavaScript (No data available in table) Pin
ZurdoDev27-Aug-19 1:06
professionalZurdoDev27-Aug-19 1:06 
SuggestionRe: Error bind data to html datatable with WebMethod and JavaScript (No data available in table) Pin
Richard Deeming27-Aug-19 3:00
mveRichard Deeming27-Aug-19 3:00 
QuestionHow to print from android web browser to Bluetooth thermal printer? Pin
enifsolutions21-Aug-19 18:44
enifsolutions21-Aug-19 18:44 
QuestionRe: How to print from android web browser to Bluetooth thermal printer? Pin
Richard MacCutchan21-Aug-19 22:20
mveRichard MacCutchan21-Aug-19 22:20 
QuestionRazor Pages Navigation Pin
Mycroft Holmes19-Aug-19 15:26
professionalMycroft Holmes19-Aug-19 15:26 
AnswerRe: Razor Pages Navigation Pin
F-ES Sitecore19-Aug-19 23:11
professionalF-ES Sitecore19-Aug-19 23:11 
GeneralRe: Razor Pages Navigation Pin
Mycroft Holmes20-Aug-19 14:59
professionalMycroft Holmes20-Aug-19 14:59 
AnswerRe: Razor Pages Navigation Pin
Richard Deeming20-Aug-19 1:59
mveRichard Deeming20-Aug-19 1:59 
GeneralRe: Razor Pages Navigation Pin
Mycroft Holmes20-Aug-19 15:01
professionalMycroft Holmes20-Aug-19 15:01 
QuestionHaving Issues to logging users to active directory through web form Pin
samflex15-Aug-19 4:40
samflex15-Aug-19 4:40 
Greetings again,

I have an asp.net web app and have been tasked with validating user log in through Active Directory.

I have been working on this part now for almost two days with no success.

Here is what I have been working on.

I created a table called ADSI_Table

This table has two fields, ParamName and ParamValue:

Here is the complete table info:

ParamName               ParamValue

WindowsDomainServer	pcg.porto.loc
BaseDN	                DC=pcg, DC=porto, DC=loc (Base DN)
UserDN	                OU=InformationSystems (User DN)
GroupName	        CN=ITTESTAPP,  OU=IT-Groups, DC=pcg, DC=porto, DC=loc
AccountFilter	        sAMAccountName


The DB Server is configured to talk to Active Directory Server.

Then I am using the following C# code to query this table:

protected void btnSubmit_Click(object sender, System.EventArgs e)
  {
      if (txtUserName.Text.Trim().Equals("") || txtPassword.Text.Trim().Equals(""))
      {
          Message.Text = "Please Enter UserName/Password...";
          txtPassword.Text = "";
          txtUserName.Text = "";
      }
      else
      {
          GetADSILogin();
      }

  }
  public void GetADSILogin()
  {
      try
      {
          string strServerName = "";
          string strBaseDN = "";
          string strUserDN = "";
          string strGroupName = "";
          string strAccountFilter = "";

          //Port no for LDAP Default is 389
          string strPortNo = "389";

          Boolean blnGroupUser = false;
          //Data source string

          string source = "Data Source=myDBServerName;Initial Catalog=MyDB;user=mysusername;password=myPassword";
          //SQL statement that will be issued

          string select = "SELECT * from ADSI_Table";

          //SQL Connection
          SqlConnection conn = new SqlConnection(source);

          // Open the database connection
          conn.Open();

          // Create the SQL command...
          SqlCommand cmd = new SqlCommand(select, conn);

          //Execute Data reader
          SqlDataReader myReader = cmd.ExecuteReader();

          //Check if any rows return against user/pass
          if (myReader.HasRows)
          {
              while (myReader.Read())
              {
                  //Store the parameter's data in variables
                  string strParameterName = myReader.GetString(0).Trim();
                  string strParameterValue = myReader.GetString(1).Trim();

                  if (strParameterName.ToUpper().Equals("SERVERNAME"))
                      strServerName = strParameterValue;

                  if (strParameterName.ToUpper().Equals("BASEDN"))
                      strBaseDN = strParameterValue;

                  if (strParameterName.ToUpper().Equals("USERDN"))
                      strUserDN = strParameterValue;

                  if (strParameterName.ToUpper().Equals("GROUPNAME"))
                      strGroupName = strParameterValue;

                  if (strParameterName.ToUpper().Equals("ACCOUNTFILTER"))
                      strAccountFilter = strParameterValue;
              }
          }

          //Search for user
          DirectoryEntry deSystem = new DirectoryEntry("LDAP://" + strServerName + "/" + strUserDN + "," + strBaseDN);
          deSystem.AuthenticationType = AuthenticationTypes.Secure;
          deSystem.Username = txtUserName.Text;
          deSystem.Password = txtPassword.Text;

          //Search for account name
          string strSearch = strAccountFilter + "=" + txtUserName.Text;

          DirectorySearcher dsSystem = new DirectorySearcher(deSystem, strSearch);
          //Search subtree of UserDN

          dsSystem.SearchScope = SearchScope.Subtree;

          //Find the user data
          SearchResult srSystem = dsSystem.FindOne();

          //Pick up the user group belong to
          ResultPropertyValueCollection valcol = srSystem.Properties["memberOf"];

          if (valcol.Count > 0)
          {
              foreach (object o in valcol)
              {
                  //check user exist in Group we are searching for
                  if (o.ToString().Equals(strGroupName + "," + strBaseDN))
                  {
                      blnGroupUser = true;
                      break;
                  }
              }
          }

          if (blnGroupUser == true)
              Message.Text = "Login Sucessfull...";
          else
              Message.Text = "User Does Not Belong to Specified ADSI Group";
      }
      catch (Exception ex)
      {
          Message.Text = (ex.Message);
      }
      int i = 0;
      i = i + 1;

      if (i == 5)
      {
          Message.Text = "Login failed for 5 times. Quiting...";
          this.Close();
      }
  }


When a user attempts to login and the log in is successful, the user is redirected to search page although I have not put the redirect code yet as I am busy testing authentication.

If the user does to belong to the specified Active Directory group, the user gets the following message:

User Does Not Belong to Specified AD Group.

So far, that's all I keep getting.

I have run the AD tree and attributes the infrastructure folks who set up the AD and they have confirmed that the entries are correct.

Can someone please tell me what could be wrong with my code or am I missing a key component?

Many thanks in advance.
AnswerRe: Having Issues to logging users to active directory through web form Pin
ZurdoDev15-Aug-19 7:46
professionalZurdoDev15-Aug-19 7:46 
GeneralRe: Having Issues to logging users to active directory through web form Pin
samflex16-Aug-19 3:50
samflex16-Aug-19 3:50 
GeneralRe: Having Issues to logging users to active directory through web form Pin
ZurdoDev16-Aug-19 3:53
professionalZurdoDev16-Aug-19 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.