我可以关闭模​​拟只是一对夫妇的情况下, [英] Can I turn off impersonation just in a couple instances

查看:154
本文介绍了我可以关闭模​​拟只是一对夫妇的情况下,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在整个使用模拟的应用程序。但是,当一个用户登录的管理员,一些操作要求他们写入到服务器本身。现在,如果这些用户没有实际的服务器上的权利(有些没有),它不会让他们写。

I have an app that has impersonation used throughout. But when a user is logged in as an admin, a few operation require them to write to the server itself. Now if these users do not have rights on the actual server (some don't) it will not let them write.

我想要做的就是关掉模拟的只是一对夫妇的命令。

What I want to do is turn off impersonation for just a couple commands.

有没有办法做这样的事情?

Is there a way to do something like this?

using(HostingEnvironment.Impersonate.Off())
  //I know this isn't a command, but you get the idea?

感谢您。

推荐答案

确认应用程序池确实有你需要的正当权益。

Make sure the Application Pool do have the proper rights that you need.

然后,当你要恢复到应用程序池标识...运行以下命令:

Then, when you want to revert to the application pool identity... run the following:

private WindowsImpersonationContext context = null;
public void RevertToAppPool()
{
    try
    {
        if (!WindowsIdentity.GetCurrent().IsSystem)
        {
            context = WindowsIdentity.Impersonate(System.IntPtr.Zero);
        }
    }
    catch { }
}
public void UndoImpersonation()
{
    try
    {
        if (context != null)
        {
            context.Undo();
        }
    }
    catch { }
}

这篇关于我可以关闭模​​拟只是一对夫妇的情况下,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆