Note that there are some explanatory texts on larger screens.

plurals
  1. POSet proxy user in a GenericPrincipal, while keeping the old identity, using MVC
    primarykey
    data
    text
    <p>I have a site where I allow some users to proxy in as an other user. When they do, they should see the entire site as if they where the user they proxy in as. I do this by changing the current user object </p> <pre><code>internal static void SetProxyUser(int userID) { HttpContext.Current.User = GetGenericPrincipal(userID); } </code></pre> <p>This code works fine for me.</p> <p>On the site, to proxy in, the user selects a value in a dropdown that I render in my _layout file as such, so that it appears on all pages.</p> <pre><code> @Html.Action("SetProxyUsers", "Home") </code></pre> <p>The SetProxyUsers view looks like this: </p> <pre><code>@using (@Html.BeginForm("SetProxyUsers", "Home")) { @Html.DropDownList("ddlProxyUser", (SelectList)ViewBag.ProxyUsers_SelectList, new { onchange = "this.form.submit();" }) </code></pre> <p>}</p> <p>The controller actions for this looks like this</p> <pre><code> [HttpGet] public ActionResult SetProxyUsers() { ViewBag.ProxyUsers_SelectList = GetAvailableProxyUsers(originalUserID); return PartialView(); } [HttpPost] public ActionResult SetProxyUsers(FormCollection formCollection) { int id = int.Parse(formCollection["ddlProxyUser"]); RolesHelper.SetProxyUser(id); ViewBag.ProxyUsers_SelectList = GetAvailableProxyUsers(originalUserID); return Redirect(Request.UrlReferrer.ToString()); } </code></pre> <p>All this works (except for the originalUserID variable, which I put in here to symbolize what I want done next.</p> <p>My problem is that the values in the dropdown list are based on the logged in user. So, when I change user using the proxy, I also change the values in the proxy dropdown list (to either disappear if the "new" user isn't allowed to proxy, or to show the "new" user's list of available proxy users).</p> <p>I need to have this selectlist stay unchanged. How do I go about storing the id of the original user? I could store it in a session variable, but I don't want to mess with potential time out issues, so that's a last resort. </p> <p>Please help, and let me know if there is anything unclear with the question.</p> <p><strong>Update</strong></p> <p>I didn't realize that the <code>HttpContext</code> is set for each post. I haven't really worked with this kind of stuff before and for some reason assumed I was setting the values for the entire session (stupid, I know). However, I'm using windows authentication. How can I change the user on a more permanent basis (as long as the browser is open)? I assume I can't use FormAuthentication cookies since I'm using windows as my authentication mode, right?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload