我用过,
CommunitySystem.CurrentContext.DefaultSecurity.RemoveUser(IUser user);
删除用户(正如本期发布的答案)。
但是,这很好用。但对于一个用户来说,它给出了一个错误。异常从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);
}
是什么导致这种情况发生?
似乎下面的代码返回“空”
commentedEntity.get_Type();
有什么办法可以删除这个用户?
附加信息:
EPiServer.CommonFramework version=9.0.1
EPiServer.CMS.Core version=11.11.0
EPiServer.Community version=9.0.0