使用c#显示活动目录中的用户映像 [英] display user image from active directory with c#

查看:95
本文介绍了使用c#显示活动目录中的用户映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用c#开发的网站。

此站点将托管在我们组织的本地Intranet中。

用户通过Windows身份验证从他们的Windows ID进行身份验证。

i想要在用户访问网站时在用户的活动目录中显示图片。



请指导我方向。如果有人能给我代码,我会非常满意。提前谢谢。

解决方案

 使用系统; 
使用 System.DirectoryServices;
使用 System.Collections;
使用 System.IO;

public class ADPhoto {

public void 设置(){
尝试 {
var de = new DirectoryEntry( LDAP:// cn = username,cn = users,DC = domain,DC = com);
de.Username = username;
de.Password = password;
var forceAuth = de.NativeObject;
var fs = new FileStream( path \\photo.jpg,FileMode.Open);
var br = new BinaryReader(fs);
br.BaseStream.Seek( 0 ,SeekOrigin.Begin);
byte [] ba = new byte [br.BaseStream.Length];
ba = br.ReadBytes(( int )br.BaseStream.Length);
de.Properties [ jpegPhoto]。插入( 0 ,ba);
de.CommitChanges();
}
catch (Exception ex){
Console.WriteLine(ex.Message);
}
}


public Stream Get(){
var fs = new MemoryStream();
尝试 {
var de = new DirectoryEntry( LDAP:// cn = username,cn = users,DC = domain,DC = com的);
de.Username = username;
de.Password = password;
var forceAuth = de.NativeObject;
var wr = new BinaryWriter(fs);
byte [] bb =( byte [])de.Properties [ jpegPhoto] [ 0 ];
wr.Write(bb);
wr.Close();
}
catch (例外e){
Console.WriteLine(e.Message);
}
return fs;
}

}


您可以尝试找到解决方案这里

或者您可以浏览其他一些链接此处

i have a web site developed with c#.
this site will be hosted in the local intranet of our organization.
the users are authenticated from their windows ID using windows authentication.
i want to display the picture in the active directory of a user, when a user visits the site.

please guide me in the proper direction. if someone can give me the code, i'd be most great full. thanks in advance.

解决方案

using System;
using System.DirectoryServices;
using System.Collections;
using System.IO;

public class ADPhoto {

public void Set() {
  try {
    var de = new DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com");
    de.Username = "username";
    de.Password = "password";
    var forceAuth = de.NativeObject;
    var fs = new FileStream("path\\photo.jpg", FileMode.Open);
    var br = new BinaryReader(fs);
    br.BaseStream.Seek(0, SeekOrigin.Begin);
    byte[] ba = new byte[br.BaseStream.Length];
    ba = br.ReadBytes((int)br.BaseStream.Length);
    de.Properties["jpegPhoto"].Insert(0, ba);
    de.CommitChanges();
  }
  catch(Exception ex) {
    Console.WriteLine(ex.Message);
  }
}


public Stream Get() {
  var fs = new MemoryStream();
  try {
    var de = new DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com");
    de.Username = "username";
    de.Password = "password";
    var forceAuth = de.NativeObject;
    var wr = new BinaryWriter(fs);
    byte[] bb = (byte[])de.Properties["jpegPhoto"][0];
    wr.Write(bb);
    wr.Close();
  }
  catch (Exception e) {
    Console.WriteLine(e.Message);
  }
  return fs;
}

}


You can try the solution found here
or you can browse through some of the other links here


这篇关于使用c#显示活动目录中的用户映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆