3

以下代码在 InitializeClientContextFromName 处失败,并显示“值不在预期范围内”。它适用于另一个开发人员的机器。

我应该跟进的任何线索?我对阿兹曼一点都不熟悉……

    private List<string> SyncAzManRoles(ActiveDirectoryMembershipProvider provider)
    {
        List<string> userAzManRoles = new List<string>();

        AzAuthorizationStoreClass store = new AzAuthorizationStoreClass();
        if (store == null)
        {
            AuthTrace("Azman store is not available");
            throw new InvalidOperationException("The azman store is not available");
        }
        store.Initialize(0, ConfigurationManager.ConnectionStrings
                    ["LocalPolicyStore"].ConnectionString, null);

        IAzApplication3 app = store.OpenApplication(Security.ApplicationName, null) as IAzApplication3;
        if (app == null)
        {
            AuthTrace("Azman application is not available");
            throw new InvalidOperationException("The azman application is not available");
        }

        IAzClientContext3 clientContext = null;
        try
        {
            clientContext = app.InitializeClientContextFromName(_username,
                provider.Name, null) as IAzClientContext3;
4

1 回答 1

2

我通过使用InitializeClientContextFromToken方法而不是 InitializeClientContextFromName 解决了这个问题。

就我而言,它在 ASP.NET Web 应用程序中使用

ulong token = 0;

var principal = User as WindowsPrincipal;
if ( principal != null )
{
    var identity = (WindowsIdentity) principal.Identity;

    ViewBag.Identity = identity.Name;
    token = (ulong) identity.Token.ToInt64();
}

// Server 2008 or Vista required to use IAzClientContext3
// Using token 0 uses app pool identity
var _clientContext = (IAzClientContext3) _azManApp.InitializeClientContextFromToken( token );

如果您将零作为令牌值传入,则对于导致使用应用程序池标识的 Web 应用程序。否则,如果用户使用 WindowsIdentity 登录,则 Token 属性的值也有效。

对于桌面应用程序,您可能只使用零令牌来使用当前用户的身份。

于 2011-05-06T06:45:48.790 回答