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

I solved this by using the InitializeClientContextFromToken method instead of InitializeClientContextFromName.

In my case, it was being used inside an ASP.NET Web application

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 );

If you pass zero in as the token value, for web apps that results in using the App pool identity. Otherwise if the user is logged in with a WindowsIdentity, then the value of the Token property works too.

For a desktop application, you can probably just use a zero token to use the current user's identity.

于 2011-05-06T06:45:48.790 に答える