0

When I load the page in Experience Editor for the first time, I am able to get Context.pagemode.IsExperienceEditor as true. We have a few ajax begin forms on the page. When I call any method in the page we will be validating a filter and if it's Experience Editor then we allow access to the method, I am getting Context.PageMode.IsExperienceEditor as false invalidation method.

As a result, the 302 redirection happens resulting in CORS error. This was working fine earlier in all environments. But currently not working in a QA environment.

Note: We didn't make changes to the code at all.

3
  • DId you try this in javascript, where you have ajax calls - var isPageEditor = function(){ return !!(Sitecore && Sitecore.PageModes && Sitecore.PageModes.PageEditor); }; if(isPageEditor()) { // Write your logic here } Dec 10, 2021 at 3:45
  • 1
    I was able to resolve this issue by checking for sc_mode=edit in UrlReferrer. Dec 10, 2021 at 8:32
  • Add this as an answer and accept that. Dec 10, 2021 at 11:07

3 Answers 3

0

If you are using a Glass Mapper in your project solution then you can use the below code snippet to find out IsExperienceEditor or not:

 var isInEditMode = Html.Glass().IsInEditingMode;

You can define the above variable on top of your .cshtml view code and assign it to any HTML hidden field.

    @{
       var isInEditMode = Html.Glass().IsInEditingMode;
     }
    <input type="hidden" id="isEditMode" name="isEditMode" value="@isInEditMode" />

Now you can retrieve the above value into your javascript/JS code as:

let isExperienceMode = this.$el.querySelector('#isEditMode')
0

Try to use this code in the view and pass parameter value to Ajax call.

@{
    var value = Sitecore.Context.PageMode.IsExperienceEditor;
}

and you can use this value in hidden field.

0

I was able to resolve this issue by checking for sc_mode=edit in UrlReferrer

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.