November Happy Hour will be moved to Thursday December 5th.

Access was denied to content

Vote:
 

I have a consoled based application that imports assets (images) for the catalog products in EPI Server. 

The program creates the blob successfully but when I call the _contentRepository.Save(file, EPiServer.DataAccess.SaveAction.Publish); I get an error saying "Access was denied to content 157. The required access level was "Create, Publish""

Running the same code within Website context does not give me that acception. 

I am running the consoled based application as admin so access level should not be a problem.

Thanks,

Syed

#114271
Dec 08, 2014 23:18
Vote:
 

I was able to resolve this on saving the content by settting up the priciplal on the current thread 

WindowsIdentity myIdentity = WindowsIdentity.GetCurrent();
IPrincipal wp = new WindowsPrincipal((WindowsIdentity)myIdentity);
Thread.CurrentPrincipal = wp;

but when I try to associate the image with Variation, I get the same access issue 

var variant = (VariationContent)contentLoader.Get<VariationContent>(variantLink).CreateWritableClone();
variant.CommerceMediaCollection.Add(commerceMedia);
contentRepository.Save(variant, EPiServer.DataAccess.SaveAction.Publish);

Thanks, 

#114272
Dec 08, 2014 23:48
Vote:
 

Hi,

Did you try with contentRepository.Save(variant, EPiServer.DataAccess.SaveAction.Publish, AccessLevel.NoAccess); ?

Regards.

/Q

#114276
Dec 09, 2014 4:54
Vote:
 

That worked. Thanks Quan,

Syed

#114314
Dec 09, 2014 21:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.