Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi friends

Background of my question is a monitoring solution (SCOM) that I have to provide for others in the department.

I like to have the possibility that I can see the same what the other employes of each usergroup can see. As I'm working with more rights as the others I always have extra work that I can see what they with the limited rights can see.

I'm like to create now a small application (winform) that allows me to observe the webpage for all of the different groups in a single application with all the different point of views. All the resultsets are on the same webpage but are different for the users.

What I like to do is:
- creating an application with a tab for each usergroup.
- configure for each usergroup a "dummy" account that has the same rights as the users of the group (in fact is a member of the same windows group)
- now create a webbrowser control and using the credentials of the dummy account

Solution that I have in mind:
- creating an usercontrol that will take in the constructor the URL, the usernamen and the password
- on runtime read the configurations and create for each of the items a tab with the usercontrol

Problem:
How can I create the usercontrol in a different security context?
I was trying to use the UriBuilder with username and password but the result was not working at all.

Has anyone an idea?

best regards
Dirk
Posted
Updated 15-Nov-11 1:53am
v2

1 solution

Combine code from 2 links:
Accessing Password Protected Network Drives in Windows in C#?
A complete Impersonation Demo in C#.NET
And do folowing steps
C#
//1. Logining
IntPtr token;
IntPtr tokenD;
if (!NativeMethods.LogonUser(login.User, login.Domain, login.Password, LogonType.Interactive, LogonProvider.Default, out token))
    throw new Win32Exception();
if (!NativeMethods.DuplicateToken(token, SecurityImpersonationLevel.Impersonation, out tokenD))
    throw new Win32Exception();

//2. Profiling. You nead administranor or local account to run LoadUserProfile
ProfileInfo profileInfo = new ProfileInfo();
profileInfo.dwSize = Marshal.SizeOf(profileInfo);
profileInfo.lpUserName = login.User;
profileInfo.dwFlags = 1;
if(!NativeMethods.LoadUserProfile(tokenD, ref profileInfo))
    throw new Win32Exception();

//3. Impersonating
var identity = new WindowsIdentity(tokenD);
var context = identity.Impersonate();

//5. Create Browser
var browser = new WebBrowser();
browser.Tag = context;
browser.Navigate(new Uri("http://www.codeproject.com"));

//6. Dispose after user, can bee on WebBrowser.Disposing or try it on tabs Selection event
NativeMethods.CloseHandle(tokenD);
NativeMethods.CloseHandle(token);
NativeMethods.UnloadUserProfile(tokenD, profile.hProfile);
context.Undo();

Its old question. Maybe you have another solution? If so, please post it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900