开发者

HttpRequest Timeout exception when making http request from a class inherited from System.Configuration.Install.Installer

开发者 https://www.devze.com 2023-03-24 21:50 出处:网络
I want to launch an EXE after completing the installation, so I wrote a custom launch condition like below:

I want to launch an EXE after completing the installation, so I wrote a custom launch condition like below:

    [RunInstaller(true)]
        public class InstallerClass : System.Configuration.Install.Installer
        {    
            public InstallerClass() : base()
            {            
                this.AfterInstall += new InstallEventHandler(InstallerClass_AfterInstall);
            }        
            void InstallerClass_AfterInstall(object sender, InstallEvent开发者_开发技巧Args e)
            {
                Directory.SetCurrentDirectory(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
                ProcessStartInfo psi = new ProcessStartInfo(
                Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location) + "\\MyApp.exe");

                psi.WorkingDirectory = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location);
                psi.Verb = "runas";

                Process p = new Process();
                p.StartInfo = psi;

                p.Start();            
            }        
.
.
.        }

Issue: MyApp.exe is creating http request to get some data from server. I get Timeout exception every time if MyApp.exe get Launch from here. If I run MyApp.exe separately, it successfully creates http request without timeout. Below is the code for http request:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Timeout = TimeOut;                    
request.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = WebRequest.DefaultWebProxy;
request.UseDefaultCredentials = true;
request.AllowAutoRedirect = true;
request.KeepAlive = false;
request.Method = "HEAD";
request.SendChunked = true;                    

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
returnValue = response.StatusCode;
}

Why am I getting timeout exception? Where am I doing wrong?


When an installer runs it runs with special permissions/rights...

Perhaps you could log what the values of request.Credentials = CredentialCache.DefaultCredentials; and request.Proxy = WebRequest.DefaultWebProxy; are when running successfully versus the timeout case

0

精彩评论

暂无评论...
验证码 换一张
取 消