Developer forum

Forum » Development » Impersonation and API

Impersonation and API

Aki Ruuskanen
Reply

Hi,

I have implemented the impersonation functionality and it works as expected exept for one thing.

I have a priceprovider which gets live prices from EPR and in that provider I check if there is a SecondaryUser and if there is one I send that customer number to the webservice and get the correct price for the impersonated user:

Dynamicweb.Modules.UserManagement.User user = User.GetCurrentUser(); 

Dynamicweb.Modules.UserManagement.User secUser = user.CurrentSecondaryUser;

 

And all that works just fine. The problem occurs when the user stops the impersonation with the:

<input type="submit" name="DwExtranetRemoveSecondaryUser" id="DwExtranetRemoveSecondaryUser" value="Stoppa imitering">

It also works fine in the frontend but the "user.CurrentSecondaryUser" in the API still returns the secondary user. But in the frontend the "Global:Extranet.SecondaryUser.UserID" is not defined which is correct.

Is that a bug? The solutions is 8.4.0.8.

 

Regarsd / Aki

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Aki

That is a bug, now TFS#15812 fixed for 8.6.

Can merge it for 8.5.0.2 if you want.

You can fix it youself by adding these 2 lines to some code that listens to the post of the request("DwExtranetRemoveSecondaryUser")

Dim user As Dynamicweb.Modules.UserManagement.User = Dynamicweb.Modules.UserManagement.User.Current(Modules.UserManagement.PagePermissionLevels.Frontend)

user.CurrentSecondaryUser = Nothing

BR Nicolai

 
Aki Ruuskanen
Reply

Tried this:

Dynamicweb.Modules.UserManagement.User user = User.get_Current(Dynamicweb.Modules.UserManagement.PagePermissionLevels.Frontend);
user.CurrentSecondaryUser = null;

But with that code the "Stop Imitation" button stopped working. 

It's this line:

user.CurrentSecondaryUser = null;

That causes it to stop working. 

I added the code to a Page.Loaded notification.

 
Nicolai Høeg Pedersen
Reply

Hi Aki

You only need to execute those lines if Request.Querystring("DwExtranetRemoveSecondaryUser") has a value...

Nicolai

 
Aki Ruuskanen
Reply

Yes, I understand that. :)

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Ok. The loaded notification fires early in the pageview, causing the normal impersonation stop to work.

So change the notification to listen to Notifications.Standard.Page.AfterOutput which is in the end of the pageview process and after the normal code have fired.

Nicolai

Votes for this answer: 1
 
Aki Ruuskanen
Reply

That did it. Thanks for the help!

 

/Aki

 

You must be logged in to post in the forum