locked
Direcrory service RRS feed

  • Question

  • User-28602167 posted

    the below code giving me exception please help me by solving this

    Actually ineed to validate user credentials before login page if he passes he should directly redirected to home page not login page

     string sDomainUserName;

    sDomainUserName = User.Identity.Name.ToString();

    int SplitValue;

    SplitValue = sDomainUserName.IndexOf("\\");

    DirectoryEntry entry =

    new System.DirectoryServices.DirectoryEntry("LDAP://DomainName");

    try

    {

     

    DirectorySearcher deSearch = new

    System.DirectoryServices.DirectorySearcher(entry);

    deSearch.Filter = "(SAMAccountName=" + sDomainUserName.Substring(SplitValue + 1) + ")";

    deSearch.PropertiesToLoad.Add("Name");

    deSearch.PropertiesToLoad.Add("displayName");

    SearchResult result = deSearch.FindOne();if (result != null)

    {

    Response.Redirect("SecurePage.aspx");

    return entry;

    }

    else

    {

    Response.Redirect(
    "default.aspx");return null;

    }

     

    }

    catch (System.Runtime.InteropServices.COMException)

    {

    System.Runtime.InteropServices.
    COMException exception = new System.Runtime.InteropServices.COMException();Console.WriteLine(exception);

    }

    catch (InvalidOperationException)

    {

    InvalidOperationException InvOpEx = new InvalidOperationException();

    Console.WriteLine(InvOpEx.Message);

    }

    catch (NotSupportedException)

    {

    NotSupportedException NotSuppEx = new NotSupportedException();Console.WriteLine(NotSuppEx.Message);

    }

    return entry;

    Thursday, November 27, 2008 1:22 AM

All replies

  • User-1190926628 posted

     It would be helpful if you told us what exception you are getting.

    Thursday, November 27, 2008 7:08 AM
  • User1055287656 posted

    One problem i see with the code is the filter...try this

    filter = "(&(objectClass=person)(sAMAccountName=" + sDomainUserName.Substring(SplitValue + 1) + "))";

     

    As the other person stated, when you need help, post the code and the error.  Often that is the only way we will have enough information to help.

    Saturday, November 29, 2008 2:55 PM