Developer forum

Forum » Templates » Impersonation
René Poulsen
René Poulsen
Reply

Hi,

I've never worked with impersonation before and I'm now trying to make it work on one of our solutions. I've created a user that can impersonate a lot of other users. I've created a template that creates a select element with options of all of the users that can be impersonated:

<form method="post">
<select id="DWExtranetSecondaryUserSelector" name="DWExtranetSecondaryUserSelector">
@{
foreach (var secondaryUser in GetLoop("DWExtranetSecondaryUsers")) {
if (counter == 10) {
<option value='@secondaryUser.GetString("UserID")' selected>@secondaryUser.GetString("UserName")</option>
} else {
<option value='@secondaryUser.GetString("UserID")'>@secondaryUser.GetString("UserName")</option>
}
}
}
</select>
<input type="submit" value="Start impersonation" />
</form>

If a user is already impersonated I create this form instead:

<form method="post">
<input type="submit" name="DwExtranetRemoveSecondaryUser" id="DwExtranetRemoveSecondaryUser" value="Stop impersonation">
</form>

The impersonation select didn't seem to work to begin with, but somehow I'm impersonating a user now. I just can't stop impersonating the user - the "DwExtranetRemoveSecondaryUser" doesn't seem to work. What am I doing wrong? :-)


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi René,

 

Once logged in, if you submit to any URL + "DWExtranetSecondaryUserSelector={UserIdToImpersonate}" you should be impersonating that user (assuming you have permissions).

 

To stop impersonating do URL + "DwExtranetRemoveSecondaryUser=1" (as in 1 = true"). That's how we do it and it works for us.

 

Best Regards,

Nuno Aguiar

 
René Poulsen
René Poulsen
Reply

Hi Nuno,

Thank you for your answer.

So a simple form like this should work for stopping impersonation? If yes, then it doesn't work for me.

<form method="post">
<input type="submit" value="Stop impersonation" />
<input type="hidden" name="DwExtranetRemoveSecondaryUser" id="DwExtranetRemoveSecondaryUser" value="1" />
</form>

 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi René,

 

Yes, that basic configuration should be sufficient.

 

Best Regards,

Nuno Aguiar

 
René Poulsen
René Poulsen
Reply

Hmmm... Weird. Doesn't work here. I'm on DW 9.4.11 and the form above does not work. Should I supply the form with some other info? PageID, etc? Or do you just use a form similar to mine?

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi René,

 

Try to set the (Page) ID as a parameter. On our end we take the current URL and add the DwExtranetRemoveSecondaryUser parameter to keep the user on the same page. It works for us.

 

Best Regards,

Nuno Aguiar

 
René Poulsen
René Poulsen
Reply

I cant get this to work. Right now I think I'm impersonating another user with my user. If I write out TemplateTags() in my tempate, I can see that these two values are set, so I guess this means that I am impersonating the user set in these values.:

Ecom:Order.Customer.SecondaryUserID
Ecom:Order.Customer.SecondaryUserName

If I manually enter an url like this: /kundeportal?DwExtranetRemoveSecondaryUser=1, the two tags above still contains values for the secondaryuser.

Does the feature require a specific module on the page or something else, that I am missing? I've just set up permissions on the page and made sure that the user I use, has the right to impersonate other users.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Your original example shows a POST forum. Accessing a URL is doing a GET. Maybe it just works with a post and you're testing it incorrectly?

 

You must be logged in to post in the forum