0

Here is the code I am using to retrieve user information from AD. I do no know how to print this information to console. Please help me. Also do I need the setters and getters for this code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

namespace AD_Test.App_Start
{
public static class ADTest
    {
        public static String GetProperty(this Principal prici, String prop)
        {
            DirectoryEntry de = prici.GetUnderlyingObject() as DirectoryEntry;
            if (de.Properties.Contains(prop))
                return de.Properties[prop].Value.ToString();
            else
                return String.Empty;
        }

        public static String GetName(this Principal princi)
        {
            return princi.GetProperty("Full Name: ");
        }
        public static String GetBlazerID(this Principal principal)
        {
            return principal.GetProperty("BlazerID: ");
        }
        public static String GetDepartment(this Principal principal)
        {
            return principal.GetProperty("Department: ");
        }
        public static String GetEmail(this Principal pricipal)
        {
            return pricipal.GetProperty("Email: ");
        }
        public static String GetTitle(this Principal principal)
        {
            return principal.GetProperty("Title");
        }
    }
}
  • There is no console window in an MVC application. For Console applications you can call Console.WriteLine() but that will not do anything in MVC. See http://stackoverflow.com/questions/137660/where-does-console-writeline-go-in-asp-net for more info. – Steven Banks Nov 21 '16 at 21:49
  • @StevenBanks Thank you I was a little confused seen as I m new to C# MVC Razor. So I print it to output window of Visual Studio? – Riddhi Patel Nov 30 '16 at 14:44
  • If you want to see the output of something while you are debugging, you can use System.Diagnostics.Debug.WriteLine(...) and that will print to the VS output window. – Steven Banks Dec 02 '16 at 17:24
  • All the information I put in to the Debug.WriteLine() prints since it is a direct string but when I try to print the AD info it gives me error of null pointer exception but it verifies the user against AD and gives me error when it goes to print the information retrieved from AD.. any thoughts as to why that would be... – Riddhi Patel Dec 21 '16 at 20:04

1 Answers1

0

You can use Debug.WriteLine("My debug string here"); to print information to the console.

In case, you don't see anything, make sure DEFINE DEBUG CONSTANT is checked under Project -> Properties -> Build.

sparta93
  • 3,684
  • 5
  • 32
  • 63