London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
Hi,
The error you got was because SecurityContext.Current can be initialized properly, which itself caused by SqlContext is not properly initialized.
You can workaround this case by adding this:
DataContext.Current = new DataContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
SqlContext.Current = DataContext.Current.SqlContext;
var securityManagerInstance = SecurityContext.Current.SecurityManagerInstance;
securityManagerInstance.CreateRole("test", Enumerable.Empty<SecurityPermission>());
Regards.
/Q
I would like to setup commerce roles in the initialize module (Commerce 7.5 MVC).
But I get the error: System.NullReferenceException: Object reference not set to an instance of an object.
What should be added to the
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class RoleInitializationModule : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var securityManagerInstance = SecurityContext.Current.SecurityManagerInstance;
securityManagerInstance.CreateRole("test", Enumerable.Empty<SecurityPermission>());
}
public void Preload(string[] parameters) { }
public void Uninitialize(InitializationEngine context)
{
}
}