Umbraco 응용 프로그램 이벤트 처리기에 연결하여 ContentService.Created 이벤트를 catch 할 수 있습니다 (ContentService.Creating 이벤트는 동일한 옵션을 제공하므로 더 이상 사용되지 않습니다).
public class AppEvents : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Created += ContentService_Creating;
}
}
그런 다음 생성되는 페이지의 유형을 확인하고 현재 사용자의 UserType을에 따라 제한을 적용 할 것 만든 이벤트의 확장을 작성할 수 있습니다. 이렇게하면 이벤트를 취소하고 페이지가 생성되지 않도록 방지 할 수 있습니다.
public void ContentService_Creating(IContentService sender, Umbraco.Core.Events.NewEventArgs<IContent> e)
{
switch (e.Entity.ContentType.Alias)
{
case "ProjectAlias":
case "NewsItemAlias":
var contentService = Umbraco.Web.UmbracoContext.Current.Application.Services.ContentService;
var userTypeAlias = UmbracoContext.Current.Security.CurrentUser.UserType.Alias;
var count = contentService.GetChildren(e.Entity.ParentId).Count();
if (string.Equals(userTypeAlias, "Standard") && count >= 10)
{
e.Cancel = true;
}
else if (string.Equals(userTypeAlias, "Ultimate") && count >= 1000)
{
e.Cancel = true;
}
break;
default:
break;
}
}
이것은 테스트되지 않았지만 특정 사용자가 페이지를 만들거나 삭제하는 것을 방지하기 위해 이전에 비슷한 방법을 사용했습니다.
아주 좋아 보이는데, 나는 이것을 시도 할 것입니다. 한 가지 더, 내가 어떻게 umbraco의 백엔드에 금액을 설정할 수 있습니까? 당신은 열심히 코딩했는데 어떤 종류의 라이센스 모듈을 설정하는 속성으로 만들고 싶습니다 – Mivaweb
CMS의 사용자 유형에 사용자 정의 속성을 추가하려는 경우 쉬운 방법이 없다고 생각합니다. 그 순간에 그렇게해라. 나는 [이 질문] (http://stackoverflow.com/questions/11847272/umbraco-adding-fields-to-users-user-types?lq=1)에 대한 답변이 2 년이지만 여전히 유효하다고 생각합니다. 늙은. 데이터베이스에 새 테이블을 추가 한 다음 사용자 섹션에 사용자 정의 트리를 추가하여 API 컨트롤러를 사용하여 새 데이터베이스 테이블에 액세스 할 수 있습니다. [예제가 있습니다.] (https://github.com/perploug/UkFest-AngularJS-Demo/blob/master/App_Code/PeopleTreeController.cs). –
아쉽게도 '만든'이벤트를 취소 할 수 없습니다. –