Umbraco-尝试使用ContentService保存内容时出错
我正在使用ApplicationEventHander在应用程序启动后创建内容。这是我的密码 public class CreateContent : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { var root = applicationContext.Services.ContentService.GetRootContent(); var content = applicationContext.Services.ContentService.CreateContent("Profile", -1, "umbTextPage"); applicationContext.Services.ContentService.Save(content); base.ApplicationStarted(umbracoApplication, applicationContext); } } 公共类CreateContent:ApplicationEventHandler { 受保护的覆盖无效应用程序已启动(UmbracoApplicationBase umbracoApplication、ApplicationContext ApplicationContext) { var root=applicationContext.Services.ContentService.GetRootContent(); var content=applicationContext.Services.ContentService.CreateContent(“Profile”,-1,“umbTextPage”); applicationContext.Services.ContentService.Save(内容); base.ApplicationStarted(umbraco应用程序、applicationContext); } } [NullReferenceException:对象引用未设置为对象的实例。] Umbraco.Core.Security.AuthenticationExtensions.GetCurrentIdentity(HttpContextBase http,布尔AuthenticateQuestifNotFound)+127 Umbraco.Web.Security.WebSecurity.GetUserId()+55 Umbraco.Web.Security.WebSecurity.get\u CurrentUser()+63 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService服务、iMembracoEntity实体、IAction操作、UmbracoContext UmbracoContext、ApplicationContext ApplicationContext)+221 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService服务、iMembracoEntity实体、IAction操作、UmbracoContext UmbracoContext)+118 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService服务、iMembraCoEntity实体、IAction操作、应用上下文应用上下文)+111 Umbraco.Web.Strategies.c__DisplayClass7.b__2(IContentService sender,SaveEventArgs`1 args)+219 Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender,TEventArgs e)+0 Umbraco.Core.Events.EventExtensions.RaiseEvent(TypedEventHandler`2 eventHandler,targets args,TSender sender)+48 Umbraco.Core.Services.ContentService.Save(IContent内容、布尔值更改状态、Int32用户ID、布尔值raiseEvents)+632 Umbraco.Core.Services.ContentService.Save(IContent内容、Int32用户ID、布尔raiseEvents)+47 MyUmbraco.CreateContent.Applications已在c:\Users\duongdd\Documents\Visual Studio 2013\Projects\MyUmbraco\MyUmbraco\CreateContent.cs:19中启动 Umbraco.Core.ApplicationEventHandler.on应用程序启动(Umbraco应用程序基础Umbraco应用程序,应用程序上下文应用程序上下文)+62 Umbraco.Core.CoreBootManager.b_uu5(IApplicationEventHandler x)+79 Umbraco.Core.EnumerableExtensions.ForEach(IEnumerable`1项,Action`1 Action)+204 Umbraco.Core.CoreBootManager.Complete(操作'1 afterComplete)+185 Umbraco.Web.WebBootManager.Complete(操作'1 afterComplete)+74 Umbraco.Core.Umbraco应用程序库.StartApplication(对象发送方,事件参数e)+242 Umbraco.Core.Umbraco应用程序库.Application\u启动(对象发送方,事件参数)+40 [HttpException(0x80004005):对象引用未设置为对象的实例。] System.Web.HttpApplicationFactory.confureStartCalledForIntegratedMode(HttpContext上下文,httpapplicationapp)+572 System.Web.HttpApplication.registereventsubscriptionswithis(IntPtr-appContext,HttpContext-context,MethodInfo[]handlers)+178 System.Web.HttpApplication.InitSpecial(HttpApplicationState,MethodInfo[]处理程序,IntPtr-appContext,HttpContext-context)+218 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr-appContext,HttpContext-context)+369 System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr-appContext,HttpContext-context)+102 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+275 [HttpException(0x80004005):对象引用未设置为对象的实例。] System.Web.HttpRuntime.FirstRequestInit(HttpContext上下文)+761 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+150 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequestWR,HttpContext上下文)+245 是否有人与此错误类似,并为我提供解决方案Umbraco-尝试使用ContentService保存内容时出错,umbraco,Umbraco,我正在使用ApplicationEventHander在应用程序启动后创建内容。这是我的密码 public class CreateContent : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { var r
谢谢 对于即将发布的7.1.3补丁版本,这个问题似乎已经得到了解决,至少部分得到了解决 我之所以这样说,部分是因为我认为这里有两个问题:
public class CreateContent : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var root = applicationContext.Services.ContentService.GetRootContent();
var content = applicationContext.Services.ContentService.CreateContent("Profile", -1, "umbTextPage");
applicationContext.Services.ContentService.Save(content, 0, false);
base.ApplicationStarted(umbracoApplication, applicationContext);
}
}
请注意,applicationContext.Services.ContentService.Save(content,0,false)
包含两个额外的参数:0表示用户id(0通常是始终存在的管理员用户),false表示指定raiseEvents=false
使用这种方法应该确保代码不会调用NotificationService,然后NotificationService会引发异常
希望这有帮助 这是哪个版本的Umbraco?从堆栈跟踪中可以看出,通知服务导致了一些问题,但以前从未见过此类问题。谢谢@sitereactor。是的,你说得对。我下载了源代码并进行了调试,通知服务在尝试保存或发布内容时导致了问题。它不会从WebSecurity获取当前用户。我正在使用Umbraco 7.1.1
public class CreateContent : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var root = applicationContext.Services.ContentService.GetRootContent();
var content = applicationContext.Services.ContentService.CreateContent("Profile", -1, "umbTextPage");
applicationContext.Services.ContentService.Save(content, 0, false);
base.ApplicationStarted(umbracoApplication, applicationContext);
}
}