命令行中缺少的命令从IIS 8.5开始

时间:2014-12-09 08:13:22

标签: c# asp.net iis iis-8

我使用了自IIS 7.5以来用指南针编译SASS文件的IHttpHandler。自从升级到Windows 8.1和IIS 8.5以来,它一直没有工作,并回复了以下消息:

/*-----------------------------------------------------------------------------------------------
//
//  compass compile "theme/default/style/custom.sass" --trace --debug-info --css-dir "data/compass"
//
//  'compass' is not recognized as an internal or external command,
//  operable program or batch file.
//
//---------------------------------------------------------------------------------------------*/

这里执行流程的部分代码(ref Dado.Compass.SingleFileHandler.cs):

void IHttpHandler.ProcessRequest(HttpContext context)
{
    // Gather Compass Configuration Variables
    ReadConfiguration(context);

    string baseDir = Path.GetDirectoryName(context.Request.Path).Replace(@"\", "/");
    string fileName = Path.GetFileName(context.Request.Path);
    string command = String.Format(@"compass compile ""{0}"" --trace --debug-info --css-dir ""{1}""",
        (baseDir + "/" + fileName).Trim(new char[] { '\\', '/' }),
        _cachePath.Trim(new char[] { '\\', '/' })
    );

    ProcessStartInfo psi = new ProcessStartInfo()
    {
        FileName = "cmd.exe",
        WorkingDirectory = context.Server.MapPath("~/"),
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true,
        Arguments = "/c " + command
    };

    using (Process process = new Process { StartInfo = psi }) {
        bool hasError = false;
...

我在ApplicationPoolIdentify下运行并且已经授予了相同的权限。此外,当我尝试从cmd.exe执行命令时,指南针可用。

为什么命令出现在cmd.exe的IIS实例中?

1 个答案:

答案 0 :(得分:0)

我不知道这是否是Window 8中的新设置,但似乎现在有一个User Path变量,这是引用指南针的变量。但是,IIS进程工作者是ApplicationPoolIdentity,因此它不会收到我的用户路径规范。

解决方案是将引用位置从用户路径变量移动到系统路径变量。