LoadUser fails for default user

Aug 14, 2010 at 3:54 PM

 

// This will automatically authenticate a user when using windows authentication
            // or when the user chose "Keep me signed in" on a previous login attempt
            WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded,null);
private void Application_UserLoaded(LoadUserOperation operation)
        {
            if (operation.HasError)
                operation.MarkErrorAsHandled();
        }

 The above operation results in an error because the default User object returned from GetUser is null.

I changed the following in FormsAuthenticationService.cs:

/// The default user object.
        protected virtual TUser GetDefaultUser() {
            return new TUser(){ Name = string.Empty } ;
        }
It appears that the new user object needs to have one of it's properties initialized, or it won't get returned from the Server.