从asp.net运行控制台应用程序

时间:2014-12-17 16:50:56

标签: asp.net asp.net-web-api console-application impersonation

我有一个web api控制器方法如下:

    [HttpGet]
    public bool CreateBook(int poolType, DateTime startDate, DateTime endDate, int operation, bool enableCustomValidation,
        int maxRowCount, bool enableTimestamp, bool enableCertificateValidation)
    {
        try
        {
            ProcessStartInfo startinfo = new ProcessStartInfo();
            startinfo.FileName = ConfigurationManager.AppSettings["AccountingBookCreatorProcessPath"];
            string args =
                poolType.ToString() + " " +
                startDate.Year.ToString() + "-" + startDate.Month.ToString("00") + "-" + startDate.Day.ToString("00") + " " + 
                endDate.Year.ToString() + "-" + endDate.Month.ToString("00") + "-" + endDate.Day.ToString("00") + " " +
                operation.ToString() + " " + 
                enableCustomValidation.ToString() + " " + 
                maxRowCount.ToString() + " " + 
                enableTimestamp.ToString() + " " + 
                enableCertificateValidation.ToString();
            startinfo.Arguments = args;
            startinfo.CreateNoWindow = true;
            startinfo.UseShellExecute = false;
            startinfo.WorkingDirectory = ConfigurationManager.AppSettings["AccountingBookCreatorWorkingDirectory"];
            //startinfo.LoadUserProfile = true;
            startinfo.UserName = "username";
            System.Security.SecureString password = new System.Security.SecureString();
            foreach (char c in "password".ToCharArray())
            {
                password.AppendChar(c);
            } 
            startinfo.Password = password;
            startinfo.Domain = "domain";
            Process process = Process.Start(startinfo);

            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

在我调试时,代码运行良好,但是当我尝试在IIS下运行Web应用程序时,控制台应用程序无效。我该怎么做才能让它正常运行?

提前致谢,

0 个答案:

没有答案