0

I have created an MVC area in the solution:

Areas  
|_ CAG  
  |_ Controllers  
  |_ Models  
  |_ Views  

When published, the Areas folder goes into the root of the instance's webroot.

Here is the Area registration:

public class CAGAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "CAG";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            //to load default page when the url is '<instance>/ContentAuthoringGuide
            context.MapRoute(
                "CAG_Home",
                "CAG/{id}",
                new { controller = "CAG", action = "Index", id = UrlParameter.Optional }
            );

            context.MapRoute(
                "CAG_default",
                "CAG/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );             
        }
    }

The page URL will be https://myproject/CAG/{item-id}

This is not a Sitecore page item

In the Index method of the Controller, I can access the Sitecore items. But here Sitecore.Context.IsLoggedIn always returns false.

public ActionResult Index(string id)
{
   bool isLoggedIn = Sitecore.Context.IsLoggedIn;
   var contextSite = Sitecore.Context.Site; //returns "website"
}

I have not created any patch configs.

Using Sitecore 10.1.2

4
  • By MVC area, are you referring to this? doc.sitecore.com/xp/en/developers/101/…. Have you tried this without an MVC area type of configuration? Is this happening on your local machine or upstream? Load balanced? Nov 21, 2022 at 13:15
  • No I have not tried with an MVC Area type. It's in my local.
    – sukesh
    Nov 21, 2022 at 13:37
  • During debug, which values are you seeing for these? Sitecore.Context.User, Sitecore.Context.User.IsAuthenticated, Sitecore.Context.User.IsNullOrAnonymous(). Does IsLoggedIn return the results you expect at the HttpRequestProcessor level? Nov 21, 2022 at 13:46
  • Did not check at HttpRequestProcessor level. Commented my original RouteConfig class and used yours instead. Context user is extranet\anonymous.
    – sukesh
    Nov 21, 2022 at 14:11

1 Answer 1

1

To avoid complications with testing, make sure to use different browsers or a private browser tab if you have an auth system on the front end that's separate from the backend.

Give this a try:

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

namespace Client.Foundation.POC.Pipelines.Initialize
{
  public class InitializeRoutes : Sitecore.Mvc.Pipelines.Loader.InitializeRoutes
  {
      public override void Process(PipelineArgs args)
      {
          RouteTable.Routes.MapRoute(
              "VisitData", // Route name
              "api/visit/data",
              new { controller = "Visit", action = "Data" },
              new[] { "Client.Foundation.POC.Controllers" });
      }
  }
}
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="Client.Foundation.POC.Pipelines.Initialize.InitializeRoutes, Client.Foundation.POC" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']"/>
      </initialize>
    </pipelines>
  </sitecore>
</configuration>
2
  • Should this be a new class? Should the existing AreaRegistration remain as is?
    – sukesh
    Nov 21, 2022 at 12:35
  • 1
    Yes. The idea would be to see if you continue to experience the issue with a slightly different configuration. Nov 21, 2022 at 13:22

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.