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

  • Home
  • SEARCH
  • 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 8156933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:06:33+00:00 2026-06-06T17:06:33+00:00

I want tp build a WPF (or Windows Forms if it can solve the

  • 0

I want tp build a WPF (or Windows Forms if it can solve the problem) that can display simultaneously the same web page with different credentials (it’s testing tool for a web application with complex user action flow).

I have, by now, a very simple WPF app :

<Window x:Class="TestTool.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <WebBrowser Margin="8" Source="http://theapptotest" />
        <WebBrowser Margin="8" Source="http://theapptotest" Grid.Column="1" />
    </Grid>
</Window>

This is not the target layout of the application, but it will allows to test if my goal is possible.

The application, as expected, display side by side the same web app. However, if I log in in the first web brower control, the second is logged in too. I guess it’s because the cookies are shared for the current user.

I checked into the WebBrowser class documentation but I did not find anything useful.

How can I reach my goal?

Is it possible to “isolate” one webbrowser from the others?

Is it possible to “impersonate” a user control? Like some applications (web browser mostly) are spawning different processes, can I “spawn” processes under a different account and display it in my main window ?

Please note that I don’t have to interact with the web pages. I just want to able to switch user by changing a tab of my application (one tab per user).

PS: I’m not stick to Internet Explorer engine, if a solution exists with alternatives browsers, let me know

PS: the target application use two authentication mechanisms. A user can authenticate with Windows account, or a custom Form based authentication. if required, I can use only forms authentication (a separate cookie container would do the job, if I can plug it).

[Edit] I’ve tried to spawn with other users credentials new instances of Internet Explorer, then attach the process main window by settings its parent to one of my windows form host. This is however, very unreliable (process often crash, can’t work if any existing instance of IE is running, etc.

  • 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-06T17:06:35+00:00Added an answer on June 6, 2026 at 5:06 pm

    Ok, I finally found a way to reach my goal, with the help of Simon Mourrier previous answer.

    I’ve created a custom user control:

    Xaml part:

    <UserControl x:Class="WpfApplication1.AppIsolatedView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" SizeChanged="UserControl_SizeChanged"
                 d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded">
        <Grid>
            <WindowsFormsHost Margin="12" Name="windowsFormsHost1" />
    
        </Grid>
    </UserControl>
    

    With this code behind :

    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    
    namespace WpfApplication1
    {
        public partial class AppIsolatedView : UserControl
        {
            public AppIsolatedView()
            {
                InitializeComponent();   
                _panel = new System.Windows.Forms.Panel();
                windowsFormsHost1.Child = _panel;    
            }
    
            string url = "http://theapptotest";   
            System.Windows.Forms.Panel _panel;
            Process _process;    
    
            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                if (IsInDesignModeStatic) return; // Avoid consumer of the control to explode when in design mode
    
                ProcessStartInfo psi = new ProcessStartInfo("iexplore.exe", "-noframemerging -private \"" + url + "\"");
                _process = Process.Start(psi);
                _process.WaitForInputIdle();
                Thread.Sleep(2000);
                SetParent(_process.MainWindowHandle, _panel.Handle);
    
                // remove control box
                int style = GetWindowLong(_process.MainWindowHandle, GWL_STYLE);
                style = style & ~WS_CAPTION & ~WS_THICKFRAME;
                SetWindowLong(_process.MainWindowHandle, GWL_STYLE, style);
    
                // resize embedded application & refresh
                ResizeEmbeddedApp();
    
            }
    
            private void UserControl_Unloaded(object sender, RoutedEventArgs e)
            {
                if (_process != null)
                {
                    _process.Refresh();
                    _process.Close();
                }
    
            }
    
            private void ResizeEmbeddedApp()
            {
                if (_process == null)
                    return;
    
                SetWindowPos(_process.MainWindowHandle, IntPtr.Zero, 0, 0, (int)_panel.ClientSize.Width, (int)_panel.ClientSize.Height, SWP_NOZORDER | SWP_NOACTIVATE);
            }
    
            protected override Size MeasureOverride(Size availableSize)
            {
                Size size = base.MeasureOverride(availableSize);
                ResizeEmbeddedApp();
                return size;
            }
    
            private static bool? _isInDesignMode;
    
            /// <summary>
            /// Gets a value indicating whether the control is in design mode (running in Blend
            /// or Visual Studio).
            /// </summary>
            public static bool IsInDesignModeStatic
            {
                get
                {
                    if (!_isInDesignMode.HasValue)
                    {
    #if SILVERLIGHT
                _isInDesignMode = DesignerProperties.IsInDesignTool;
    #else
                        var prop = DesignerProperties.IsInDesignModeProperty;
                        _isInDesignMode
                            = (bool)DependencyPropertyDescriptor
                            .FromProperty(prop, typeof(FrameworkElement))
                            .Metadata.DefaultValue;
    #endif
                    }
    
                    return _isInDesignMode.Value;
                }
            }
    
            private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                ResizeEmbeddedApp();
    
            }
            #region pinvoke stuff
            [DllImport("user32.dll")]
            private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
            [DllImport("user32.dll", SetLastError = true)]
            private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            [DllImport("user32")]
            private static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent);
    
            [DllImport("user32")]
            private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
    
            private const int SWP_NOZORDER = 0x0004;
            private const int SWP_NOACTIVATE = 0x0010;
            private const int GWL_STYLE = -16;
            private const int WS_CAPTION = 0x00C00000;
            private const int WS_THICKFRAME = 0x00040000;
            #endregion
            }
    }
    

    I have to cheat a bit :

    • I have to add -noframemerging when firing IExplore.exe in order to avoid internal IE session sharing.
    • I have to sleep a bit after having launch the process. Don’t know exactly why, but the MainWindowHandle property change after some few milliseconds (I guess iexplore has a bootstrapper process to either connect to existing process or spawn a new one, with new handle, or something like this).

    I still have to extend the user control to accept input parameters (url is hardcoded), but the idea is here. I just have to concentrate on the app itself.

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

Sidebar

Related Questions

I want to build flash application that can detect the user eyes color and
I'm trying to build a UI layout in WPF that can scale with the
I'm working on a WPF app where i want to display the built-in windows
I have a WPF Control Library that is being added to a windows forms
I want to build a WPF Application that, when started, only has a tray
I want build a sketch pad app on iPhone, I assume that this type
I want to build a form_tag that will allow me to post a new
I want to build a python program that deletes all the photos from my
I want to build a basic Client-Server application, where my android smartphone can stream
I am trying to build a WPF application (using C#.net) in which I want

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.