4

我有一个使用 Kerberos 访问使用 ASP.NET 3.5 和 IIS 的外部资源的 Web 应用程序。

当用户连接到应用程序时,Kerberos 身份验证自动神奇地允许我使用委托连接到充当用户的外部资源。这并不容易做到。这很好,但我有一个问题。有时我需要使用比用户拥有更多权限的帐户连接到外部资源。运行应用程序池的服务帐户具有我需要的添加权限。如何删除用户的 Kerberos 标识并使用运行应用程序池的服务帐户连接 Kerberos?

更新

我不知道为什么我没有得到任何回应。我以前从未见过。请发布问题,他们可能会澄清问题(对我来说也是)。


在 Kerberos 中工作并且需要对委派的概述?阅读此答案的第一部分:https ://stackoverflow.com/a/19103747/215752 。

4

1 回答 1

7

我有一堂课:

public class ProcessIdentityScope : IDisposable
{
    private System.Security.Principal.WindowsImpersonationContext _impersonationContext;
    private bool _disposed;

    public ProcessIdentityScope()
    {
        _impersonationContext = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
    }

    #region IDisposable Members

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (!_disposed)
        {
            _impersonationContext.Undo();
            _impersonationContext.Dispose();
            _disposed = true;
        }
        else
            throw new ObjectDisposedException("ProcessIdentityScope");
    }

    #endregion
}

我像这样使用它:

using(ProcessIdentityScope identityScope = new ProcessIdentityScope())
{
    // Any code in here runs under the Process Identity.
}

此代码基于此 MSDN 文章:http: //msdn.microsoft.com/en-us/library/ms998351.aspx

于 2010-01-19T22:44:27.480 回答