views:

38

answers:

1

given 1. the initial idea, link text and 2. creating nested loops link text

can I use linq here or how should I massage this to authenticate WindowsPrincipal to sql table? Thanks, -greg

protected void Page_Load(object sender, EventArgs e)
{
    string UserIdentityName = Server.HtmlEncode(User.Identity.Name);  
    Boolean Match = CompareUserName(UserIdentityName);
}

private Boolean CompareUserName(string PassedInValue)
{
    VerifyUserNameDataContext db = new VerifyUserNameDataContext();
    char[] delimiterChars = { ' ', ',', '.', ':', '\t' , '\\' };
    string[] words = PassedInValue.Split(delimiterChars);

    foreach (string split_up_domain_username in words)  
    {
       foreach (User users in db.Users) 
       {
            var user = (from u in db.Users
                        where u.Name.ToString() == split_up_domain_username.ToString()
                        select u).First();
            if (user != null) return true;
        }
    }
    return false;
}
A: 

Use Enumerable.SingleOrDefault rather than Enumerable.First

var user = (from u in db.Users where u.Name.ToString() == split_up_domain_username.ToString() select u).SingleOrDefault();