gpt4 book ai didi

c# - AZMan:InitializeClientContextFromName 失败,返回 "Value does not fall within the expected range."

转载 作者:行者123 更新时间:2023-11-30 17:18:14 27 4
gpt4 key购买 nike

以下代码在 InitializeClientContextFromName 处失败,显示“值不在预期范围内。”它可以在其他开发人员的机器上运行。

有什么线索我应该跟进吗?我对 AzMan 一点都不熟悉......

    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;

最佳答案

我使用 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 );

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

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

关于c# - AZMan:InitializeClientContextFromName 失败,返回 "Value does not fall within the expected range.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5895814/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com