一旦應用程序啓動,我正在使用ApplicationEventHanlder創建內容。這裏是我的代碼Umbraco - 嘗試使用ContentService保存內容時出現錯誤
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); } }
[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Core.Security.AuthenticationExtensions.GetCurrentIdentity(HttpContextBase http, Boolean authenticateRequestIfNotFound) +127 Umbraco.Web.Security.WebSecurity.GetUserId() +55 Umbraco.Web.Security.WebSecurity.get_CurrentUser() +63 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext) +221 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext) +118 Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, ApplicationContext applicationContext) +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, TArgs args, TSender sender) +48 Umbraco.Core.Services.ContentService.Save(IContent content, Boolean changeState, Int32 userId, Boolean raiseEvents) +632 Umbraco.Core.Services.ContentService.Save(IContent content, Int32 userId, Boolean raiseEvents) +47 MyUmbraco.CreateContent.ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) in c:\Users\duongdd\Documents\Visual Studio 2013\Projects\MyUmbraco\MyUmbraco\CreateContent.cs:19 Umbraco.Core.ApplicationEventHandler.OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) +62 Umbraco.Core.CoreBootManager.b__5(IApplicationEventHandler x) +79 Umbraco.Core.EnumerableExtensions.ForEach(IEnumerable`1 items, Action`1 action) +204 Umbraco.Core.CoreBootManager.Complete(Action`1 afterComplete) +185 Umbraco.Web.WebBootManager.Complete(Action`1 afterComplete) +74 Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e) +242 Umbraco.Core.UmbracoApplicationBase.Application_Start(Object sender, EventArgs e) +40 [HttpException (0x80004005): Object reference not set to an instance of an object.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +572 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +178 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, 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): Object reference not set to an instance of an object.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +761 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +150 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +245
是任何人都與此類似的錯誤,並提供給我一個解決方案嗎?
謝謝!
哪個版本的Umbraco是這個?從堆棧跟蹤看來,通知服務正在導致一些問題,但之前沒有看到過這種類型的問題。 – sitereactor
感謝@sitereactor。是的,你是對的。我下載了源代碼並進行了調試,通知服務在嘗試保存或發佈內容時導致問題。它不會從WebSecurity獲取當前用戶。 我使用Umbraco 7.1.1 –