以下代码在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;发布于 2011-05-06 14:45:49
我通过使用InitializeClientContextFromToken方法而不是InitializeClientContextFromName解决了这个问题。
在我的例子中,它是在ASP.NET网络应用程序中使用的
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属性的值也有效。
对于桌面应用程序,您可能只需使用零令牌来使用当前用户的身份。
https://stackoverflow.com/questions/5895814
复制相似问题