我用过
CommunitySystem.CurrentContext.DefaultSecurity.RemoveUser(IUser user);
删除用户(就像在this issue中发布的答案一样)。
但是,这很好。但是对于一个用户,它给出了一个错误。 RemoveUser(IUser user)
引发异常。
异常详细信息如下,
System.ArgumentNullException: The type cannot be null. Parameter name: type
at EPiServer.Data.Entity.Internal.EntityTypeResolver.GetTypeName(Type type, Boolean ignoreOverrideAttribute)
at EPiServer.Common.ImplementationModule.HandleCommentAddUpdateRemove(IComment comment, SupportedOperations operation)
at EPiServer.Common.Comments.CommentHandler.OnCommentUpdated(IComment comment)
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0()
at EPiServer.Common.Comments.CommentHandler.UpdateComment(IComment comment)
at EPiServer.Common.Data.FrameworkFactoryBase.CascadeUpdateStatus(IEntityStatus entity, ICollection`1 children)
at EPiServer.Common.Data.CommentFactory.CascadeAuthorStatus(IAuthor author)
at EPiServer.Common.AuthorEventHandler.Invoke(EntityEventArgs args)
at EPiServer.Common.AuthorHandler.OnAuthorUpdated(IAuthor author)
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0()
at EPiServer.Common.AuthorHandler.UpdateAuthor(IAuthor author)
at EPiServer.Common.Data.FrameworkFactoryBase.CascadeUpdateStatus(IEntityStatus entity, ICollection`1 children)
at EPiServer.Common.Security.Data.SecurityFactory.<>c__DisplayClass57_0.b__0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0()
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
at EPiServer.Common.Security.SecurityHandler.RemoveUser(IUser user)
我尝试提取Type
和类型名称,并且效果很好。
IUser user = getUser(id);
Type type = user.AccessRightsType;
string typeName = new EPiServer.Data.Entity.Internal.EntityTypeResolver().GetTypeName(type, true); // Not null. This value is as same as on other users
更新:我已经反编译了EPiServer.Common.ImplementationModule
,这就是HandleCommentAddUpdateRemove(..)
的内容。
private static void HandleCommentAddUpdateRemove(IComment comment, SupportedOperations operation) {
EntityReference commentedEntity = comment.CommentedEntity;
IComment comment2 = null;
CommentEventData commentEventData;
if ((int) operation == 4) {
comment2 = (IComment) comment.get_Master();
if (comment2 == null || comment2.Status == comment.Status) {
return;
}
commentedEntity = comment2.CommentedEntity;
commentEventData = new CommentEventData(IEntityTypeResolverExtensions.GetTypeName(ServiceLocator.get_Current().GetInstance < IEntityTypeResolver > (), commentedEntity.get_Type()), commentedEntity.get_ID(), comment2.Status, -1);
m_commentEvent.Raise(m_commentId, (object) commentEventData);
}
commentEventData = new CommentEventData(IEntityTypeResolverExtensions.GetTypeName(ServiceLocator.get_Current().GetInstance < IEntityTypeResolver > (), commentedEntity.get_Type()), commentedEntity.get_ID(), comment.Status, ((int) operation != 8) ? 1 : (-1));
m_commentEvent.Raise(m_commentId, (object) commentEventData);
}
什么原因导致这种情况发生?
似乎下面的代码返回“ Null”
commentedEntity.get_Type();
是否可以删除该用户?
其他信息:
EPiServer.CommonFramework version=9.0.1
EPiServer.CMS.Core version=11.11.0
EPiServer.Community version=9.0.0