Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tommy Albinsson 121 posts 254 karma points
    Apr 19, 2011 @ 10:57
    Tommy Albinsson
    0

    Problem with custom membership and role provider

    Hi,

    In a recent project we have decided to use umbraco for a intranet solution. There is a number of posts describing the problem with umbraco as a intrenet and AD autentication. But we decided to give it a try anyway. Our goal was to create a multiprovider that lets us use the umbraco backend as usual and also use the umbraco methods for useraccess on the site.

    Both of these scenarios work and all the AD groups load perfectly into the umbraco backend and so on, but there is a couple of problems that i can't wrap my head around. When recycling the applicationpool or doing something that makes the site recycle i am always presented with the same exception. Also if i am to quick on refreshing i am presented with "unable to load appdomain", but this does not happen everytime.

    Could not load file or assembly 'Examine.XmlSerializers' or one of its dependencies. The system cannot find the file specified.

    [FileNotFoundException: Could not load file or assembly 'Examine.XmlSerializers' or one of its dependencies. The system cannot find the file specified.]
       System.DirectoryServices.AccountManagement.IADsPathname.Retrieve(Int32 lnFormatType) +0
       System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo() +1144
       System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsDomainName() +110
       System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p) +251
       System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups() +53
       EEL.Intranet.code.ADRoleProvider.GetRolesForUser(String username) +559

    [ProviderException: Unable to query Active Directory.]
       EEL.Intranet.code.ADRoleProvider.GetRolesForUser(String username) +1783
       System.Web.Security.RolePrincipal.IsInRole(String role) +249
       System.Web.Configuration.AuthorizationRule.IsTheUserInAnyRole(StringCollection roles, IPrincipal principal) +184
       System.Web.Configuration.AuthorizationRule.IsUserAllowed(IPrincipal user, String verb) +445
       System.Web.Configuration.AuthorizationRuleCollection.IsUserAllowed(IPrincipal user, String verb) +241
       System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +11335444
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +266

     

    I can't get my head around why it is trying to load examine. For a test i included all the dll files in the solution for my provider but that did not help. I will provide the GetRolesForUser code below. If any more code is neede i just say so and i will post that also.

    public override String[] GetRolesForUser(String username)
            {
                // If SQL Caching is enabled, try to pull a cached value.
                if (_EnableSqlCache)
                {
                    String CachedValue;
                    CachedValue = GetCacheItem('U', username);
                    if (CachedValue != "*NotCached")
                    {
                        return CachedValue.Split(',');
                    }
                }
                ArrayList results = new ArrayList();
                using (PrincipalContext context = new PrincipalContext(ContextType.Domain, null, _DomainDN))
                {
                    try
                    {
                        UserPrincipal p = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
                        var groups = p.GetAuthorizationGroups();
                        foreach (GroupPrincipal group in groups)
                        {
                            if (!_GroupsToIgnore.Contains(group.SamAccountName))
                            {
                                if (_IsAdditiveGroupMode)
                                {
                                    if (_GroupsToUse.Contains(group.SamAccountName))
                                    {
                                        results.Add(group.SamAccountName);
                                    }
                                }
                                else
                                {
                                    results.Add(group.SamAccountName);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ProviderException("Unable to query Active Directory.", ex);
                    }
                }
                // If SQL Caching is enabled, send value to cache
                if (_EnableSqlCache)
                {
                    SetCacheItem('U', username, ArrayListToCSString(results));
                }

                return results.ToArray(typeof(String)) as String[];
            }

     

    Thankful for any help at all. Cheers.

  • Tommy Albinsson 121 posts 254 karma points
    Apr 28, 2011 @ 14:23
    Tommy Albinsson
    0

    After many hours of pulling my hair, i finally found a solution to my problem. I am not at all satisfied with the solution, and maybe someone can give me a tip to fix it som other way.

    I fixed it by delaying the FindByIdentity method and GetAuthorizationGroups methods like this.

                        Thread.Sleep(6000);
                       
                        UserPrincipal p = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
                        var groups = p.GetAuthorizationGroups();

                        Thread.Sleep(3000);

    When doing this i do not get the exception anymore. So it seems that maybe Examine has not been loaded before or is done loading. Does someone got any other tips that i can try?

    Cheers.

  • Nick Van Eeckhout 2 posts 22 karma points
    May 05, 2011 @ 12:28
    Nick Van Eeckhout
    0

    I had the same issue (although with a different assembly) and posted the issue as a question on stackoverflow:
    http://stackoverflow.com/questions/5895128/attempted-to-access-an-unloaded-appdomain-when-using-system-directoryservices

  • Tommy Albinsson 121 posts 254 karma points
    May 11, 2011 @ 20:33
    Tommy Albinsson
    0

    Seems like we have the same problem, though no one has got a real solution yet :(

Please Sign in or register to post replies

Write your reply to:

Draft