3

I am using Sitecore on azure and have a CD and a CM server.

The Web API works fine on CM but throws a 404 error (and no more information in logs).

I have deleted the following dll files from server as recommended in Sitecore documentation,

Sitecore.ExperienceAnalytics.dll
Sitecore.ExperienceAnalytics.Client.dll
Sitecore.ExperienceAnalytics.ReAggregation.dll

I found a line in the Sitecore.config that might be helpful but refers to a file I cannot find on any server,

<handler trigger="~/api/" handler="sitecore_api.ashx" />

To go further into my research of the source of the problem, I would need to know if the web API feature is linked to a particular dll or config file I can investigate, or even the fix if someone has already encountered the problem.

  • can you try to enable Sitecore.Speak.Mvc.config on CD just for test ? are you web api calls starting with /api/sitecore/ ? – Vlad Iobagiu Jun 12 '17 at 16:33
  • @SitecoreClimber, enabling the Sitecore.Speak.Mvc.config did the trick. Thank you very much for your help ! – Aloïs de La Comble Jun 13 '17 at 7:11
  • I will change my comment into an answer. I will give you some details, is not a good practice to enable that file. – Vlad Iobagiu Jun 13 '17 at 7:12
4

One option is to enable Sitecore.Speak.Mvc.Config file .

In the Sitecore.Speak.Mvc.config file, the InitializeCommandRoute processor maps the /api/sitecore/{controller}/{action} route for SPEAK UI Applications, which are used by Sitecore Content Management installation. Probably your ajax call are using /api/sitecore.

If there is not a specific reason why your AJAX calls start with /api/sitecore/ prefix, please register a custom route using the standard ASP.NET MVC approach through Initialize pipeline.

2

I have encountered the same problem today while working on a function via sitecore api which is hosted in sitecore azure paas project. Hence, just to share. I have created the following:

JS file

<script>
    function showDiv() {
        var email = $("#email_id").val();

        $.ajax({
            type: "POST",
            url: "/api/Accounts/GetEmailAddress",
            data: { "email": email },
            success: function (r) {
                if (r.trim().length > 0) {
                    document.getElementById('cta-thankyou').style.display = "block";
                    document.getElementById('cta').style.display = "none";
                }
            }, error: function (error) {
                alert('error; ' + eval(error));
            }
        });

    }
</script>

RegisterWebApiRoutes.cs

using System.Web.Mvc;
using System.Web.Routing;
using Sitecore.Pipelines;

namespace PROJECTABC.Feature.Accounts.Infrastructure.Pipelines
{
    public class RegisterWebApiRoutes
    {
        public void Process(PipelineArgs args)
        {
            RouteTable.Routes.MapRoute("PROJECTABC.Feature.Accounts.Api", "api/Accounts/{action}", new
            {
                controller = "Accounts"
            });
        }
    }
}

App_Config\Include\Feature\PROJECTABC.Feature.Accounts.config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <initialize>
                <processor type="PROJECTABC.Feature.Accounts.Infrastructure.Pipelines.RegisterWebApiRoutes, PROJECTABC.Feature.Accounts" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" resolve="true" />
            </initialize>
        </pipelines>
    </sitecore>
</configuration>

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.