是否可以从javascript查询AD?
我在SharePoint中工作,我可以使用我在博客上找到的一些js来获取当前SharePoint用户的信息.
但我想知道我是否可以查询AD以查看当前用户是否在特定的AD组中.
我正在尝试创建一个自定义HttpModule,它控制哪些用户可以查看网站.
我正在尝试利用Windows身份验证来执行此操作.
在单个页面上,我可能会这样做:
if (HttpContext.Current.User.Identity.Name.Contains("jsmith"))
{
Response.Write("You do not have the correct permissions to view this site.");
Response.End();
}
Run Code Online (Sandbox Code Playgroud)
但是因为我想在应用程序级别使其更易于配置,所以我想使用HttpModule.
这是我对代码的开始:
using System;
using System.Web;
public class CustomAuthHttpModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
context.EndRequest += new EventHandler(OnEndRequest);
}
void OnBeginRequest(object sender, EventArgs e) { }
void OnEndRequest(object sender, EventArgs e)
{
HttpApplication appObject = (HttpApplication)sender;
HttpContext contextObject = appObject.Context;
if (contextObject.User.Identity.Name.Contains("jsmith"))
{
contextObject.Response.Clear();
contextObject.Response.End();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我可以将它放在OnBeginRequest()函数中,我可以使用我拥有的代码.但是在OnEndRequest()运行之前,不会在HttpContext对象中创建User属性. …