0

My current Sitecore(9.0.2) project have multisite implementation with URL structure as follows

We have to use a common Sitecore component for SubSite, Site1, and Site2. the component has Ajax form posting and for this, I have added a single route entry for each of the APIs as follows:

    routes.MapRoute(
           name: "routeName",
           url: "{virtualFolder}/api/ContrrolerName/ActionName",
           defaults: new { controller = "Test", action = "action", id = UrlParameter.Optional });

The above routing is perfectly working for SubSite and when used on Site1 it is returning a 404 error during Ajax post. However, it is working correctly when I removed SubSite from URL ie, www.MainSite.com/Site1.

So I understand that {virtualFolder} is not returning the path defined on siteconfig file. It is returning only the last part.

Anybody help me to resolve this issue

1 Answer 1

1

You need to define separate routes for entries like that:

routes.MapRoute(
        name: "routeNameVirtualFolder",
        url: "{virtualFolder}/api/ContrrolerName/ActionName",
        defaults: new { controller = "Test", action = "action", id = UrlParameter.Optional }
                   );
routes.MapRoute(
        name: "routeNameVirtualSubFolder",
        url: "{virtualFolder}/{virtualSubFolder}/api/ContrrolerName/ActionName",
        defaults: new { controller = "Test", action = "action", id = UrlParameter.Optional }
                   );
1
  • Thanks @marek it is working
    – shahul
    May 4, 2023 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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