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
2010-10-14 13:13:50
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
2010-10-14 18:01:32
I fixes this issue.
Mikhail
2010-10-14 18:02:51