0

In my application, an admin can log in as another user. If he logs in as such user, a new window should open in a new tab, where he is logged in as this user. So it should be open then two tabs, once where the admin is logged in and a tab where the admin is logged in as the user. I have no idea how i can do this. Controller:

public class AdminController: Controller
{
    Uow uow = new Uow();
    public ActionResult Index(AdminViewModel am)
    {

        am.UserList = uow.RepUser.Get().ToList();

        return View(am);
    }

    public ActionResult LoginAs(int id )
    {

        var user = uow.RepUser.Get(x => x.UserId == id).FirstOrDefault();
        LoginViewModel lvm = new LoginViewModel();

        lvm.Username = user.Username;
        lvm.Password = user.Password;
        Session["User"] = user;
        Session["UserID"] = user.UserId;           

        FormsAuthentication.SetAuthCookie(lvm.Username, false);

        return RedirectToAction("Index","Home",lvm);
    }

}

View:

<div>
<table id="customers">


    <tr>
        <th>Benutzername</th>
        <th>Vorname</th>
        <th>Nachname</th>
        <th>Kläranlage</th>
        <th>Aktion</th>
    </tr>

            @for (int i = 0; i < Model.UserList.Count(); i++)
        {
                <tr>
                    @Html.HiddenFor(modelItem =>Model.UserList[i].UserId)
                    <td>@Html.DisplayFor(modelItem => Model.UserList[i].Username)</td>
                    <td>@Html.DisplayFor(modelItem => Model.UserList[i].FirstName)</td>
                    <td>@Html.DisplayFor(modelItem => Model.UserList[i].LastName)</td>
                    <td>@Html.DisplayFor(modelItem => Model.UserList[i].SewagePlant)</td>
                    <td>@Html.ActionLink("Log in as ","LoginAs", new {id=Model.UserList[i].UserId},null)</td>

                </tr>
            }

</table>

Thanks for helping

Phill
  • 17
  • 6
  • 1
    The server cannot control what 'tabs' are opened. That has to be done in the browser, and even that is controller by user settings in their browser ([Open a URL in a new tab (and not a new window)](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript)) –  Feb 12 '18 at 01:18
  • You can add a function "View as" like in Facebook. – Red Wei Feb 12 '18 at 01:57
  • Technically you have to execute client function on your view. simple way is making your login function with Ajax then on success you can open tabs based on your requirement. – mzonerz Feb 12 '18 at 11:24

0 Answers0