ASP.Net 获取登陆用户信息方法
2009-05-31 17:22
971 查看
工作需要,asp程序需要获取访问用户的相关信息。查阅大量资料,记录以收藏
1)通过office interop控件可以获取,但发现这种方法并不适用于server端(此方法可在之前帖子中找到)。
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
2)寻找过其他替代方法,但这些方法需要用户名和密码登陆通过OWA获取,这并不是在server端很好的办法,该方法可参阅:
1. http://weblogs.asp.net/whaggard/archive/2007/01/30/how-do-i-access-my-outlook-contacts-from-my-web-application.aspx
2. http://blogs.msdn.com/webdav_101/archive/2008/06/11/getting-a-list-of-mailboxes.aspx
3)通过Active Directory方式可以获取企业域内的相关信息,域内的服务器可以直接获取而不需要特定用户名密码登陆。
参阅:http://weblogs.asp.net/jpinquie/archive/2008/02/06/how-to-get-domain-user-information-from-active-directory-in-c.aspx
http://www.codeproject.com/KB/exchange/AccessGAL.aspx
主要实现:
using System.DirectoryServices;
string filter = "(&(objectCategory=person)(SAMAccountName=alias))";
DirectorySearcher searcher = new DirectorySearcher(filter);
foreach (SearchResult result in searcher.FindAll())
{
// Do work with data returned for each address entry
DirectoryEntry entry = result.GetDirectoryEntry();
Console.WriteLine("Name: {0} {1}/nEmail: {2}/nPhone: {3}/nDisplayName:{4}",
entry.Properties["givenName"].Value,
entry.Properties["sn"].Value,
entry.Properties["mail"].Value,
entry.Properties["telephonenumber"].Value,
entry.Properties["displayname"].Value
);
//if the properties has more than 1 items, use the method below
if (entry.Properties["memberof"].Count > 0)
{
for (int i = 0; i < entry.Properties["memberof"].Count; i++)
{
string group = entry.Properties["memberof"][i].ToString();
if (group.StartsWith("CN="))
{
group = group.Substring(3, group.IndexOf(',') - 3);
}
//Console.WriteLine(entry.Properties["memberof"][i].ToString());
Console.WriteLine("======"+group+"=============");
}
}
1)通过office interop控件可以获取,但发现这种方法并不适用于server端(此方法可在之前帖子中找到)。
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
2)寻找过其他替代方法,但这些方法需要用户名和密码登陆通过OWA获取,这并不是在server端很好的办法,该方法可参阅:
1. http://weblogs.asp.net/whaggard/archive/2007/01/30/how-do-i-access-my-outlook-contacts-from-my-web-application.aspx
2. http://blogs.msdn.com/webdav_101/archive/2008/06/11/getting-a-list-of-mailboxes.aspx
3)通过Active Directory方式可以获取企业域内的相关信息,域内的服务器可以直接获取而不需要特定用户名密码登陆。
参阅:http://weblogs.asp.net/jpinquie/archive/2008/02/06/how-to-get-domain-user-information-from-active-directory-in-c.aspx
http://www.codeproject.com/KB/exchange/AccessGAL.aspx
主要实现:
using System.DirectoryServices;
string filter = "(&(objectCategory=person)(SAMAccountName=alias))";
DirectorySearcher searcher = new DirectorySearcher(filter);
foreach (SearchResult result in searcher.FindAll())
{
// Do work with data returned for each address entry
DirectoryEntry entry = result.GetDirectoryEntry();
Console.WriteLine("Name: {0} {1}/nEmail: {2}/nPhone: {3}/nDisplayName:{4}",
entry.Properties["givenName"].Value,
entry.Properties["sn"].Value,
entry.Properties["mail"].Value,
entry.Properties["telephonenumber"].Value,
entry.Properties["displayname"].Value
);
//if the properties has more than 1 items, use the method below
if (entry.Properties["memberof"].Count > 0)
{
for (int i = 0; i < entry.Properties["memberof"].Count; i++)
{
string group = entry.Properties["memberof"][i].ToString();
if (group.StartsWith("CN="))
{
group = group.Substring(3, group.IndexOf(',') - 3);
}
//Console.WriteLine(entry.Properties["memberof"][i].ToString());
Console.WriteLine("======"+group+"=============");
}
}
相关文章推荐
- asp.net IIS 部署报错/获取不到当前用户信息 配置方法
- 有关ASP.NET如果获取登陆用户信息问题
- C# B/S程序中出现“异常详细信息: System.Data.SqlClient.SqlException: 用户 'XXX/ASPNET' 登录失败。”的处理方法
- (转)asp.net获取访问用户IP地址信息的类
- Asp.net Request方法获取客户端的信息
- ASP.NET 2.0防止同一用户同时登陆方法三(转)
- asp.net 使用ffmpeg.exe获取视频信息并截图方法类
- 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
- asp.net 2.0防止同一用户同时登陆(方法一)
- Asp.net Request方法获取客户端的信息
- (微信公众号开发《一》OAuth2.0网页授权认证获取用户的详细信息,实现自动登陆)http://blog.csdn.net/liaohaojian/article/details/70175835
- ASP .NET MVC 微信授权获取用户信息并实现登录
- 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
- ASP.NET获取当前用户的方法属性大整合
- [ASP.NET]Request获取url信息的各种方法比较
- ASP.NET获取服务器信息方法
- ASP.NET获取当前用户的方法属性大整合
- asp.net中获取客户端IP地址网卡信息等方法的代码
- ASP.NET获取IP及电脑名等信息的简单方法+通用类文件源码
- 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法.