IIS7 integrated mode closing token between requests

发布于 2022-09-06 12:19:18 字数 710 浏览 46 评论 0

We are migrating to IIS7 integrated mode and have come across an issue. We authenticate using WindowsAuthentication but then store a reference to the WindowsPrincipal so that on future requests we can authorize as needed against AD. In IIS 7 Integrated mode, the token is being closed (between requests) so that when we try to run IsInRole it generates a disposed exception. Is there a way to cache this token or change our use of WindowsPrincipal so that we don't need to make successive AD requests to get it for each authorization request?

Here is the exception being thrown from WindowsPrincipal.IsInRole("") - System.ObjectDisposedException: {"Safe handle has been closed"}

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

违心° 2022-09-13 12:19:19

Have you tried letting IIS cache the auth information for you?

Check out the options for the section of web.config. Specifically the authPersistNonNTLM and authPersistSingleRequest attributes. PersistNonNTLM=True may do exactly what you need w/o any custom implementation in your code.

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

故人爱我别走 2022-09-13 12:19:19

In AcquireRequestState event handler I just touched the HttpContext.Current.User.Identity.Name as below

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

and in my WCF services I could use the Identity and the Profile, without a ObjectDisposedException.

I don't know why.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文