简体   繁体   中英

How to check if the user is not logging to a Domain account

The following code will check for the user when the user select a Domain account by selecting a value from the txtboxDomain.Text

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, txtboxDomain.Text))
{
    // validate the credentials
    bool isValid = pc.ValidateCredentials(txtboxUsername.Text, txtboxPassword.Text);
    if (isValid == true)
    {
        lblLogin.Text = "Valid User Name and/or Password";
        Session["Person"] = txtboxUsername.Text;
        Session.Timeout = 1;
        Response.Redirect("default.htm");
    }
    else
    {
        lblLogin.Text = "Invalid User Name and/or Password";
    }
}

So, how do I code so that if the user only want to use the local system account? (Suppose that the local system name is WIN2008R2_LOCAL ?

Do I write the code as using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "WIN2008R2_LOCAL"))

(I tried the above code but it does not work. So wondering how should I code then.)

PrincipalContext pc = new PrincipalContext(ContextType.Machine, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM