Question
· Sep 1, 2016

Multiple namespaces in web application

I've noticed that Management portal somehow manages to allow a single user to be in different namespaces in different tabs in the same application (i.e. Management Portal).  I've looked at my Processes, however, and see that all of my processes using MgmtPortal think I'm in %SYS, even though 2 of them are looking at globals in two different namespaces; NamespaceA and NamespaceB.  

 

I can even fool MgmtPortal because the first time I try to look at a global in NamespaceA it thinks I'm in %SYS!  After a refresh, however, I can see the global in NamespaceA.  

 

How does MgmtPortal do this?  This is what I'm trying to achieve with my own web application (hopefully minus the fooling).  GroupById doesn't seem to work (I have a separate web application for each namespace, and a different GroupById for each web application -- didn't seem to allow more than one namespace for one user).

 

I don't want to use CSPShare, as it comes with all sorts of warnings.  I'm thinking of a Login cookie, but don't know how to do that yet. 

 

IS programmers: does MgmtPortal do this programmatically?  Is there a check in the code that keeps the display and the namespace in sync?

 

Thanks,

Laura

Discussion (8)0
Log in or sign up to continue

You can change namespace in Caché ObjectScript with:

Set $Namespace = "SomeOtherNamespace"

In methods that do that, it's typically good to start out with:

New $Namespace

To ensure that the namespace switches back once it's out of that context. Of course, you need to be sure that any code you call is available in the new namespace, and it would be good to think carefully about security implications.

The management portal uses the $NAMESPACE parameter in the URL along with %request.Context to add it to other URLs so you stay in the same namespace across pages.

OK.  I know how to switch namespaces.  What I'm trying to achieve is if the user opens another tab or browser, the two sessions share namespace, but I don't want them to.  Change to NamespaceB in one, and the other changes to NamespaceB as well, without the user knowning.

 

In MgmtPortal, I can change to ENSEMBLE in one tab, but the other tab stays in DEMO.  (However, my processes all think I'm in %SYS becuase the third tab viewing the processes is in %SYS -- bug??)  Watch out - if you try to view a global in DEMO, at first it will think you're in %SYS. Try it (I'm on 2014).

 

But after that inital hiccup, MgmtPortal allows one tab to switch namespaces without changing the other tab. how? How does one do that using web applications?

Laura,

Unless you are using web sockets, whenever someone makes a request from a web client it will issue a call back to the Caché server and it will be handled by a csp process which will spin up and go to a namespace and get the appropriate session variables, etc.  If I understand properly what you are looking to do, you could store the namespace as a session variable and then on each of your pages you can test the session variable on the request and reset to a different namespace if it isn't the default.  I believe that this is how the SMP does it (or something very similar).

HTH,

Ben

Well, I'm not a web programmer, and I don't know anything about web sockets.  So let's go with "not using".

 

We do store the namespace in the %session.Data variable.  howver, it's possible to chnage the namespace while on a second tab, and then when you come back and file data, oops, you're filing it into the wrong namespace.  

 

We'll just have to implement checks with the %session variable, perhaps a URL parameter, and what namespace the user thinks he's in based on a field on the screen.  

 

In the meantime, I'm going to have to say "no second tabs, even though it can make you feel more productive to work on separate clients/applications at one time".

 

Sigh.  Thanks.

I think I better understand now - you want 'other' tabs to dynamically update (without the user hitting Refresh) if the user changed namespaces in a separate tab, is that correct?

I think there are probably Javascript events that fire when a tab comes back into focus (you'd have to check) and you could use those to trigger a call to the server to see if the namespace has changed - if it has then redraw the tab to show the context of the proper namespace.  It would have more moving parts but it should be possible if you really want to do it.

Good luck!

Ok, it's really easy to mess up MgmtPortal; however, I do see the $NAMESPACE=namespace in the URL (at times).  Although not completely consistent (try it - so easy to confuse it), at least it gives you a starting point of where the user thinks  you should be.

Is that the only way mgmt portal knows?  Is it switching namespaces on the other tabs every time you change one tab?  Or is it keeping the tabs' namespaces separate?

Playing around with it a little bit, I came to the following conclusions:

- *some* pages rely on the $Namespace url parameter in order to initialize what namespace it is pulling data from

- this doesn't appear to be stored in the session (and therefore it isn't shared between tab); I think it is only effective in the url

- there are some pages which don't honor the $Namespace url parameter (e.g. they still show %SYS even if $Namespace is defined to a different value); this is probably because those pages don't act on any namespace-specific data (or they act on data which lives ONLY in %SYS)

It sounds like if you want to keep your tabs in sync, you should put something in the session, and switch namespaces in your page logic.  Probably in OnPreHttp (although you'd need to test to make sure that the namespace sticks for the OnPage method as well)