I want to destroy the session when the user clicks the fa-fa-close icon.

I tried by creating an ajax call and destroy the session.

But when I calling ajax method this method throws an error.

Can anyone help why this has happened?

enter image description here

enter image description here

  • 1- Never user /api/sitecore 2- RenderingContext will be null in ajax request
    – Abhay Dhar
    Jan 30, 2020 at 9:33
  • Then How I call my controller back ?
    – Rajasekar
    Jan 30, 2020 at 9:54
  • There is no need to use renderingcontext ,you can use Sitecore.Contexxt.Item or GetItem , also configure a seperate route , dont use /api/sitecore , it will break in your CD server
    – Abhay Dhar
    Jan 31, 2020 at 5:44

2 Answers 2


Use RenderingContext.CurrentOrNull if you need to test for the existence of the rendering context rather than RenderingContext.Current. If you have no current rendering context (ie an ajax call) then attempts to read RenderingContext.Current throw an exception. I know you're doing a null check on it, but if it is null it will throw an exception when reading it, just one of those Sitecore oddities.


Based on your error, the controller is getting called but since the RenderingContext is null the error is being thrown. The RenderingContext is always null in AJAX call.


public Item ContextItem = Sitecore.Context.Item;

That should solve your issue. Let me know in case you need any further help.

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.