Solved

created an empty class and need to call it form a form1 which is in th the same windows application.

Posted on 2008-06-24
3
220 Views
Last Modified: 2013-12-16
using System;
using System.Collections.Generic;
using System.Text;

namespace InitialPrices
{
    class AuthenticateActiveDirectory
    {
        public bool UserExistInActiveDirectory ()
        {
        string sPath = "LDAP://peach/dc=wpg,dc=cwb,dc=ca";
        string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
        string[] parts = fullname.Split('\\');
        string sDomain = parts[0];
        string sUser = parts[1];
        string sGroup = "gl ca corporate data";
           
        InitialPrices.InitialPriceReportingServiceWS.InitialPriceReportingService WS =
            new InitialPrices.InitialPriceReportingServiceWS.InitialPriceReportingService();
        if ((sUser == "gtgifford") || (sUser == "mxcupryk") || (sUser == "ggervais"))
        {
            return (true);
        }
        else
        {
                return( WS.CheckUserAgainstGroupMembers(sPath, sDomain, sGroup, sUser));

        }
        }
    }
}

Need to fix the above so I can call it from my form1.cs
0
Comment
Question by:mathieu_cupryk
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
burakiewicz earned 500 total points
ID: 21855759
if you use this you should be able to call it on the form
AuthenticateActiveDirectory aad = new AuthenticateActiveDirectory();
aad.UserExistInActiveDirectory ();

if you change to this
public bool UserExistInActiveDirectory ()  to
public static bool UserExistInActiveDirectory ()

then you can call by
AuthenticateActiveDirectory.UserExistInActiveDirectory ();
0
 

Author Comment

by:mathieu_cupryk
ID: 21856000

i should create a constructor and also public class?

namespace InitialPrices
{
      class AuthenticateActiveDirectory
      {
            public static bool UserExistInActiveDirectory ()
            {
            string sPath = "LDAP://peach/dc=wpg,dc=cwb,dc=ca";
            string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
            string[] parts = fullname.Split('\\');
            string sDomain = parts[0];
            string sUser = parts[1];
            string sGroup = "gl ca corporate data";
               
            InitialPrices.InitialPriceReportingServiceWS.InitialPriceReportingService WS =
                  new InitialPrices.InitialPriceReportingServiceWS.InitialPriceReportingService();
            if ((sUser == "gtgifford") || (sUser == "mxcupryk") || (sUser == "ggervais"))
            {
                  return (true);
            }
            else
            {
                        return( WS.CheckUserAgainstGroupMembers(sPath, sDomain, sGroup, sUser));

            }
            }
      }
}
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21856133
if you have it as static like in your code, you should be able to call it from the form, if not make the class public..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now