I have a requirement,

When clicking the close I need to destroy the user session. For this, I have created an ajax call to destroy the session.

For calling controller with the Sitecore context, I have created a custom route to update the controller action method.

But when I call this method the injected method calls automatically(In the controller that I injected and throws a null exception)

Custom route class:

enter image description here


enter image description here

The error that I'm facing:

enter image description here

The injected method from the controller:

enter image description here

  • Did you add this controller in dependency injection? – Gaurav Agarwal Feb 3 at 6:41
  • Where do I need to add? Pls, specify the location? – Rajasekar Feb 3 at 6:52
  • the error is self explanatory - Please check ItemExtensions.cs, method GetAncestors orSelfOfTemplate() and which item is pased to it – Abhay Dhar Feb 3 at 7:04
  • Can you share your full code snippet for the controller – Hishaam Namooya Feb 3 at 10:23
  • 1
    Your custom routing works fine. An error is in PageContentRepository constructor, when GetSiteRoot() method is hitting. I think that the issue is because of you do something with ContextItem that is null in ajax calls. – x3mxray Feb 3 at 12:40

The controller code you've linked above doesn't actually show were the error is. I've encountered similar instances before where the context was missing. Those solutions generally involved doing one of the following:

  1. Passing the context item ID in as a query string parameter.
  2. Setting withCredentials to true in the ajax call so that cookies/context is sent over.
  3. wrap the methods in a SiteContextSwitcher
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.