0

我们正在迁移到 IIS7 集成模式并且遇到了一个问题。我们使用 WindowsAuthentication 进行身份验证,然后存储对 WindowsPrincipal 的引用,以便在将来的请求中,我们可以根据需要对 AD 进行授权。在 IIS 7 集成模式下,令牌正在关闭(在请求之间),因此当我们尝试运行 IsInRole 时,它​​会生成一个已处理的异常。有没有办法缓存这个令牌或改变我们对 WindowsPrincipal 的使用,这样我们就不需要为每个授权请求发出连续的 AD 请求来获取它?

这是从 WindowsPrincipal.IsInRole("") 引发的异常 - System.ObjectDisposedException: {"Safe handle has been closed"}

谢谢。

4

2 回答 2

0

您是否尝试过让 IIS 为您缓存身份验证信息?

查看 web.config 部分的选项。特别是authPersistNonNTLMandauthPersistSingleRequest属性。PersistNonNTLM=True 可以完全满足您的需求,而无需在代码中使用任何自定义实现。

http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication

于 2011-02-08T01:08:00.960 回答
0

AcquireRequestState事件处理程序中,我刚刚触摸了HttpContext.Current.User.Identity.Name如下

var t = HttpContext.Current.User.Identity.Name;
var p = HttpContext.Current.Profile;

在我的 WCF 服务中,我可以使用IdentityProfile,而没有ObjectDisposedException.

我不知道为什么。

于 2012-09-04T14:31:23.650 回答