How do you "sense" that you are in backoffice- and/or editmode?

I want to “sense” that you are in backoffice and/or editmode. How do I do this?

Code:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class B2BAuthorizationAttribute : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        var isAuthenticated = httpContext.User.Identity.IsAuthenticated;
        if (!isAuthenticated)
        {
            return false;
        }

        var personStorage = IoC.Resolve<PersonStorage>();
        if (personStorage.CurrentSelectedOrganization != null || SecurityToken.CurrentSecurityToken.IsSystemUser)
        {
            return true;
        }

        var loginService = IoC.Resolve<LoginService>();
        loginService.Logout();
        return false;
    }
}

Litium version: 7.3.2

Describe the scenario please, what are you trying to achieve?

The RouteRequestLookupInfo object has a property .IsInAdministration that’s set to true when visiting a page in back office. Maybe that’s enough for your use case?

I want to force the customer to be connected to a organization when not in backoffice, otherwise we log them out.

Is that really available in a Attribute though?

You can use IoC to resolve it.
var routeRequestLookupInfo = IoC.Resolve<RouteRequestLookupInfoAccessor>().RouteRequestLookupInfo;

You can see it in OrganizationRoleAttribute class in the default Accelerator.

I just figured that out when you wrote back :slight_smile:

Thanks

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.