views:

90

answers:

1

My situation:

I'm running a C# testing program which allows me to configure certain browser "steps", like going to an URL or clicking on a button. There's also the posibility to enter a domain, username and password. When running the program it will invoke another program* with the (if entered) username and password. This new program will run Internet Explorer (through Watin) and perform the "steps".

The problem here is that when I go to a URL which requires a certain user, it will give me "You are not authorized to view this page". When I manually (Internet Explorer - Run As) login with the same user (and i checked the credentials more than once) it will give me authorization just fine.

Something I allready tested: when running a localhost page (which would display the current user) I get authorization both manually and automatically through the program. Oh and: the program runs fine when I do not configure the credentials (it will skip the if statement)

The code I use to launch the second program:

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
            if (!string.IsNullOrEmpty(Username))
            {
                System.Security.SecureString secPw = new System.Security.SecureString();
                foreach (char c in Password)
                {
                    secPw.AppendChar(c);
                }
                psi.UserName = Username;
                psi.Password = secPw;
                psi.Domain = Domain;
            }
            psi.WorkingDirectory = "c:\\temp";
            psi.FileName = Path.Combine("c:\\temp", fileName);
            psi.Arguments = xmlStepFilename;
            psi.UseShellExecute = false;
            psi.EnvironmentVariables["TMP"] = "c:\\temp";

            var process = new System.Diagnostics.Process();
            process.StartInfo = psi;
            process.Start();

Thank you for your time!

(* The new program was implemented, because Internet explorer would always run under the user the initial application was started with, and it didn't seem possible to run Internet Explorer with another username/password because Watin did not support this... But that is not part of the problem)

A: 

psi.LoadUserProfile = true; is the right answer. It seems we have a professional in the house :) Thank Commander Keen!

Jon Koeter
You're welcome..
thijs