Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7911683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:20:32+00:00 2026-06-03T13:20:32+00:00

I am trying to implement an admin feature on my site that allows an

  • 0

I am trying to implement an admin feature on my site that allows an admin to impersonate a user by inputting their username (to see what they see).

Right now I have this setup as a jQueryUi dialog in the _LogOn partial view in the _Layout master view since this will be on every page. However, I am not sure what to do at this point due to some issues I’ve never dealt with before.

1) I need to run a check to see if the inputted username exists, if it doesn’t it should display a message in the dialog’s form.

2) I need to reload the entire page (so what is being displayed changes due to the new user updates) after submitting.

3) The box should appear open again after the page reloads. After the dialog form is submitted.

So I don’t know how to implement this because partials have no controllers, nor do I know how to make a jquery box reappear based on if the submit came from that specific form nor how to get an error message up when the partial isn’t based on a model. Then I thought about making the form AJAX, but I am not sure how to do that either since the entire page eventually has to be reloaded to update the display.

The addition to _LogOn partial besides the default code:

if (SessionUtil.IsSiteAdmin)
{
    <button id="impersonate" style="position: relative; right: 20px; float: left; top: -30px;">Impersonate</button>
    <div id="impersonate-user" title="Admin User Impersonation">
        @using (Html.BeginForm())
        {
            <p>Currently Impersonating: 
                @if (SessionUtil.User.Id != SessionUtil.UserAbsolute.Id)
                {
                    <text>
                    @SessionUtil.User.FirstName @SessionUtil.User.LastName (@SessionUtil.User.NetId)
                    </text>
                }
                else
                {
                    <text>None</text>
                }
            </p>
            <p>@Html.ActionLink("Stop Impersonating", "StopImpersonating", "Shared", new { area = "", @class = "ui-button ui-widget ui-state-default ui-corner-all" })</p>
            <div>
                <div id="ValidationSummary">
                @Html.ValidationSummary(true)
                </div>
                <fieldset>
                    <div class="editor-label">
                        @Html.Label("Username to Impersonate")
                    </div>
                    <div class="editor-field">
                        @Html.TextBox("Username")
                    </div>

                    <p>
                        <input type="submit" value="Impersonate"/>
                    </p>
                </fieldset>
            </div>
        }
    </div>
}

The JS:

 <script type="text/javascript">
        $("#impersonate-user").dialog({
            autoOpen: false,
            modal: false,
            width: 400,
            height: 505,
            closeOnEscape: true,
            resizable: false,
            draggable: true
        });
        $("#impersonate")
            .button()
            .click(function () {
                $("#impersonate-user").dialog("open");
                $('.ui-dialog :button, .ui-dialog a').blur();
            });
    </script>

Can someone tell me how to do this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:20:34+00:00Added an answer on June 3, 2026 at 1:20 pm

    I would recommend using ajax to do the name lookup and show an error message if it’s not found. No need to reload the page for a failure.

    It looks like you’re using jQuery, so for #1 and #2:

    $.ajax({
         url: actionUrl,
         data: { username: username },
         success: function() {
             window.location = window.location // I think this will refresh the page
         },
         error: function(error) {
             alert('username not found');  // do what you have to do
         }
    });
    

    What I would do for your case is have an action that you call with the above Ajax. If the username exists, it sets some flags in session, e.g.: Session["IsImpersonating"] = true and then you could have a block in your page that checks the session, and shows the dialog again:

    @if ((bool)Session["IsImpersonating"]) // null check omitted
    {
         <script>
               $(function() {
                     $("#myDialog").dialog();
               });
         </script>
    }
    

    FYI, to run an action with a partial, I think you just have to do the following:

    @Html.Action("MyAction", "MyController")
    

    This will make a call back to the server, just as if you did a regular page load, and plop the HTML for whatever view it returns onto the page.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement selectbox in my site.Option for that selectbox is set
We're trying to implement formsAuthentication on our site, but in a scenario that we
I am trying to implement CKEditor in my CakePHP app admin section with a
when trying to implement an Aspect, that is responsible for catching and logging a
I am trying to implement admin login and operators(india, australia, america) login, now operator
I am trying to implement WordPress into quite a large site with a complex
I have a little slideshow that I am trying to implement in a Sharepoint
I'm trying to implement conflict detection in an admin system i.e. Alice is editing
I am trying to implement basic user/roles A user can have zero to many
I am trying to implement Users loggin in on the homepage of the site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.