在任何地方使用Active Directory映像

2023-11-20

介绍 (Introduction)

Active Directory has a neat feature that enables you to upload user images. Unfortunately not all systems support reading these user images natively and writing code involves manipulating a byte array and memory stream which not everybody is comfortable in doing.

Active Directory具有一项简洁的功能,使您可以上传用户图像。 不幸的是,并非所有系统都支持本地读取这些用户图像,并且编写代码涉及操纵并非所有人都习惯的字节数组和内存流。

This simple web application should suffice as both a solution for those that want to simply display images in their web applications, using an HTML <IMG> tag or as a starter project if you would like to enhance it.

对于那些只想使用HTML <IMG>标记在其Web应用程序中简单显示图像的解决方案,如果想对其进行增强,则此简单的Web应用程序就足够了。

演示版 (Demo)

演示地址

()

代码 (The Code)

GitHub repo address: https://github.com/svermaak/UserPhotos.git

GitHub仓库地址https : //github.com/svermaak/UserPhotos.git

using System;
using System.Configuration;
using System.DirectoryServices;
using System.IO;
using System.Web;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sAMAccountName = Request.QueryString["SAMAccountName"];

Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpeg";
Response.BinaryWrite(GetUserPicture(sAMAccountName));
Response.Flush();
Response.End();
}
private byte[] GetUserPicture(string sAMAccountName)
{
byte[] returnValue;
try
{
// Get configuration
string domainFQDN = ConfigurationManager.AppSettings["DomainFQDN"];
string domainDN = ConfigurationManager.AppSettings["DomainDN"];
string domainNetBIOS = ConfigurationManager.AppSettings["DomainNetBIOS"];
string domainUserName = ConfigurationManager.AppSettings["DomainUserName"];
string domainPassword = ConfigurationManager.AppSettings["DomainPassword"];

DirectoryEntry directoryEntry;
if ((!string.IsNullOrEmpty(domainNetBIOS)) && (!string.IsNullOrEmpty(domainUserName)) && (!string.IsNullOrEmpty(domainPassword)))
{
// Using credentials from Web.Config
directoryEntry = new DirectoryEntry($@"LDAP://{domainFQDN}/{domainDN}", $"{domainNetBIOS}\\{domainUserName}", $"{domainPassword}");
}
else
{
// Using Application Pool Identity
directoryEntry = new DirectoryEntry($@"LDAP://{domainFQDN}/{domainDN}");
}

DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry)
{
Filter = string.Format("(&(SAMAccountName={0}))", sAMAccountName)
};
SearchResult user = directorySearcher.FindOne();
returnValue = user.Properties["thumbnailPhoto"][0] as byte[];
}
catch
{
// Handles error and default image
System.Drawing.Image img = System.Drawing.Image.FromFile($@"{HttpRuntime.AppDomainAppPath}\DefaultImage.png");
img = img.GetThumbnailImage(370, 370, null, IntPtr.Zero);
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
returnValue = ms.ToArray();
}
}
return returnValue;
}
} 

部署 (deployment)

Simply open the solution in Visual Studio and publish it on an IIS server. Building a Visual Studio project and publishing of a site is outside of the scope of this article.

只需在Visual Studio中打开解决方案并将其发布在IIS服务器上即可。 构建Visual Studio项目和发布网站不在本文讨论范围之内。

After publishing, edit the web.config and change these values appropriately. If you do not specify a username and password, the Application Pool's identity will be used

发布后,编辑web.config并适当更改这些值。 如果您未指定用户名和密码,则将使用应用程序池的身份

<add key="DomainFQDN" value="ittelligence.com" />
<add key="DomainDN" value="DC=ITtelligence,DC=com" />
<add key="DomainNetBIOS" value="ITtelligence" />
<add key="DomainUserName" value="" />
<add key="DomainPassword" value="" /> 

结论 (Conclusion)

I hope you found this tutorial useful. You are encouraged to ask questions, report any bugs or make any other comments about it below.

希望本教程对您有所帮助。 鼓励您在下面提出问题,报告任何错误或对此作出任何其他评论。

Note: If you need further "Support" about this topic, please consider using the Ask a Question feature of Experts Exchange. I monitor questions asked and would be pleased to provide any additional support required in questions asked in this manner, along with other EE experts...  

注意 :如果您需要有关此主题的更多“支持”,请考虑使用Experts Exchange 的“提问”功能。 我会监督提出的问题,并很高兴与其他电子工程师一起提供以这种方式提出的问题所需的任何其他支持...

Please do not forget to press the "Thumbs Up" button if you think this article was helpful and valuable for EE members.

如果您认为本文对EE成员有用且有价值,请不要忘记按下“竖起大拇指”按钮。

It also provides me with positive feedback. Thank you!

它还为我提供了积极的反馈。 谢谢!

翻译自: https://www.experts-exchange.com/articles/33495/Use-Active-Directory-Images-Anywhere.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在任何地方使用Active Directory映像 的相关文章

随机推荐

  • Docker搭建mysql主从

    目录 1 安装配置master 1 1 运行mysql容器 1 2 更新基础软件和安装vim 1 3 编辑配置文件 1 4 创建用户并授权 用于再主从库之间同步数据 2 slave数据库安装配置 2 1 运行容器 2 2 进入容器内部 2
  • JavaWeb的高级、Listener监听器--Servlet事件

    一 学习目标 1 Listener监听器 2 Listener监听器作用 3 Listener监听器的创建与销毁 二 重点知识 1 Listener监听器 Filter和Listener是Servlet规范中的两个高级特性 不同于Servl
  • vue项目打包后如何本都部署访问

    npm run build生成dist项目后 在windows部署访问 方式一 1 新建一个文件夹 进入目录后打开cmd 输入npm init y 2 输入 npm i express s 是用于在 Node js 项目中安装 Expres
  • 小程序实现微信登录Java后端(一)--前端实现

    目录 一 概述 二 登录流程 三 前端代码 四 解读前端代码 1 登录部分 2 检查当前用户是否已登录 3 小程序启动时校验登录 五 阶段性小结 一 概述 最近终于有时间去搞一下准备参加比赛的小程序 小程序一开始设计的是使用邮箱登录 老师建
  • 剑指offer——输出数组中k个最小值(快速,冒泡,选择,插入)

    找k个最小值 基本思路是对数组排序 输出前k个或者后k个 我们回顾一下之前的学习过的集中排序方法 快速排序 class Solution def GetLeastNumbers Solution self tinput k def quic
  • rust房屋建造蓝图_妄想山海房子建造攻略

    妄想山海这个游戏的一大特色就是玩家可以在游戏里建造属于自己的房屋 而且这个房屋可不是几个图或是简单的3d模型 而是一个完整的房屋呦 玩家可以创作或是收集来的房屋设计图 真实打造 所以在妄想山海里房子的建造还是要花点功夫的 下面讯喵喵就为大家
  • Redis 分布式缓存

    分布式缓存 单点 Redis 的问题及解决 数据丢失 实现Redis数据持久化 并发能力 搭建主从集群 实现读写分离 存储能力 搭建分片集群 利用插槽机制实现动态扩容 故障恢复能力 利用哨兵机制 实现健康检测和自动恢复 RDB RDB全称R
  • 利用接口请求获取文件

    1 背景 测试阶段文件上传服务器为测试文件服务器 预览时根据id获取的测试服务器文件 但发到线上后发现文件上传到了测试服务器 读取文件时又是从线上的文件服务器读取的 因此导致了文件显示异常 2 数据恢复分析 先从测试环境获取到文件 这些文件
  • 微信小程序图片使用filter将彩色图片变成黑白以后,border-radius失效的解决办法

    使用css的filter将彩色图片亮度降低之后 设置的border radius会出现失效不起作用的情况 需求 用户在线头像为原始的彩色图片 离线将用户头像改为黑白色 原来的写法
  • 【数据结构】并查集

    文章目录 1 并查集原理 2 并查集的实现 2 1并查集框架 2 2insert 插入元素接口 2 3Findroot查找所属集合 2 4合并两个集合 2 5统计集合个数 3 测试 4 并查集OJ 4 1省份的数量 4 2等式方程的可满足性
  • Enterprise Architect 中文经典教程

    本文使用到的EA工程文件下载 一 Enterprise Architect简介 Enterprise Architect是一个对于软件系统开发有着极好支持的CASE软件 Computer Aided Software Engineering
  • python从键盘上输入一个字符、当输入的是英文字母时_从键盘输入一个字符 若该字符是英文字母是则输入对应的ASCII码...

    展开全部 ascill字母表 a z 97 122 A Z 65 90 0 9 48 57 代码如下 可以循环判断是字母的ascil 输入636f707962616964757a686964616f313333376261340退出 inc
  • 验证微信号的正则表达式

    var wxreg a zA Z 1 a zA Z0 9 5 19
  • vue项目使用视频播放器vue-video-player

    安装使用 插件有版本限制 如果项目使用的是vue2 0版本 请选择安装 4 x版本 否则会安装不成功 yarn add vue video palyer save 或者 npm install vue video palyer save 组
  • python里出现breakoutsideloop_Python ast.Break方法代码示例

    本文整理汇总了Python中ast Break方法的典型用法代码示例 如果您正苦于以下问题 Python ast Break方法的具体用法 Python ast Break怎么用 Python ast Break使用的例子 那么恭喜您 这里
  • Java对JSON路径解析JsonPath例子

    1 jsonpath的特点 不需要定义java bean 不用对多层map多次迭代 就可以获得json解析树中深层次的节点 Jayway的jsonpath解析需要把要解析的json一次加载进内存 2 1 jsonpath表达式的两种方式 t
  • html创建添加地图(超简单)

    1 打开百度地图创建平台 百度地图创建平台 2 根据个人需求改就行了 可加标注 3 点击获取代码 复制下来就可以用了 4 个人用的是HBulider 复制到里面可直接用了 如果有文字显示问题 把编码改成utf 8就行了 5 地图控件位置在网
  • Unity3d + NGUI 的多分辨率适配

    移动端的多机型适配 现在要介绍的是 锁链战记 这款游戏的适配方法 这种适配方法是UI是一个基础尺寸 背景是一个基础尺寸 背景比UI多出的部分是一些没有实际作用的部分 这样的适配方式避免了在iPhone5这样的小屏幕上镶边 首先设定UIRoo
  • matlab函数式里虚数i怎么表示,matlab虚数_matlab 中复数如何表示?

    matlab 中复数如何表示 你i是不是已经被定义为变量了 正常i就是复数单位 可以这样表示的 matlab是否可以定义虚数 想来想去只想到一个比较笨的办法 不过不用if find和循环语句 而且确实管用 a 1 2 3 3i 2i 1i
  • 在任何地方使用Active Directory映像

    介绍 Introduction Active Directory has a neat feature that enables you to upload user images Unfortunately not all systems