views:

18

answers:

2

How i can get Current User. And how i can validate user via Active Directory by user and pass.

A: 

You should use ASP.NET authentification to achieve this. In order to implement this, I would strongly recommend you to use something as RIA Services, which contains all the plumbing required to enable ASP.NET authentification in a Silverlight App.

With ASP.NET auth enabled, you will be able to edit your config file to use a AD identity provider, as in any other ASP.NET web app.

More informations about the ActiveDirectoryMembershipProvider on MSDN

Maupertuis
A: 
[OperationContract]
    public string GetCurrentUserWindowsLogin()
    {
        return Environment.UserName;
    }

    [OperationContract()]
    public User DoLogIn(string login, string password)
    {

        string userName = String.Format(@"ELEGION\{0}", login);
        string SERVER = "LDAP://Caesar.elegion.local";

        User user = null;

        try
        {
            DirectoryEntry entry = new DirectoryEntry(SERVER, userName, password, AuthenticationTypes.ReadonlyServer);
            object nativeObject = entry.NativeObject;

            if (nativeObject != null)
            {
                HeRMeSSunRiseDBEntities ent = EntitySingleton.Entities;
                user = ent.Users.Where(l => l.Login == login && l.IsDisabled == false).FirstOrDefault();
                if (user != null)
                {
                    user.ADObject = entry.Guid.ToString();
                    ent.SaveChanges();
                    return user;
                }
            }
        }
        catch (DirectoryServicesCOMException cex)
        {
            Debug.Write(cex.Message);
        }
        catch (Exception ex)
        {
            Debug.Write(ex.Message);
        }



        return user;}
Mikhail
I fixes this issue.
Mikhail