开发者

WCF Service throws error when validating Credentials against PrincipalContext?

I have a WCF service, which works if I use one login, but throws the following error if I try logging in with any other login. Strangely enough, if I change the password to the working login, the new password doesn't work but the old one still does. It's almost like it is caching something.

The error I get is this:

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

The code that causes the error is this:

public UserModel Login(string username, string password)
{
    if (username == null || password == null)
        return null;

    using (var pContext = new PrincipalContext(ContextType.Machine))
    { 
        if (pContext.ValidateCredentials(username, password))
        {
            using (var context = new MyEntities())
            {
                // I can tell from a SQL trace that this piece never gets hit
                var user = (from u in context.Users
                            where u.LoginName.ToUpper() == username.ToUpper()
                                  && u.IsActive == true
                            select u).FirstOrDefault();

                if (user == null)
                    return null;

                var userModel = Mapper.Map<User, UserModel>(user);
                userModel.Token = Guid.NewGuid();
                userModel.LastActivity = DateTime.Now;

                authenticatedUsers.Add(userModel);
                sessionTimer.Start();

                return userModel;
            }
        }
    }

    return null;
}

I see a related question here, which suggests the problem is with the PrincipalContext, but no answer

Update

Got it working..... I restarted our production server because we needed to have this working for someone importa开发者_C百科nt within the next hour, and I thought since it that previous link suggested that a reboot would get a single login in that I would just reboot and login with the login needed to get it working for now, and after rebooting everything works absolutely perfectly. I spent most of yesterday, staying late, and all of this morning trying to figure this out. We're not supposed to reboot our web server, but it was important to get this working so I did it anyways, and now everything works the way it should.

I would still like to know what its problem was though. My best guess is that something caused the PrincipalContext to not dispose correctly, which was preventing me from logging in with any other set of credentials.


Restarting the server fixed the issue, although I'd still love to know what the problem was.

My best guess is that something caused the PrincipalContext to not dispose correctly, which was preventing me from logging in with any other set of credentials.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜