无法使用cmd.exe在iis托管的asp.net Web应用程序中执行命令ng build [英] Unable to execute command ng build in iis hosted asp.net web app using cmd.exe

查看:121
本文介绍了无法使用cmd.exe在iis托管的asp.net Web应用程序中执行命令ng build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#代码执行ng build来构建我的有角项目.我已经在IIS上托管了c#应用程序.当我执行代码时出现错误:

I want to execute ng build using c# code to build my angular project. I have hosted by c# application on IIS. When I am executing code I am getting error:

ng'不被识别为内部或外部命令,\ r \不可操作的程序或批处理文件.\ r \ n

ng' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n

我创建了另一个我没有托管在IIS上的应用程序,并且正在使用Visual Studio在本地执行该应用程序.在同一代码中是工作属性.我无法找出iis的问题.我的代码如下.

I have created another application that I have not hosted on IIS and I am executing that with locally using visual studio. In that same code is working property. I am unable to figure out issue with iis. My code is as below.

private void buildAngular()
        {
            try
            {

                Process p = new Process();
                p.EnableRaisingEvents = true;
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.WorkingDirectory = @"D:\AngularToBuild\AngularProject";
                p.StartInfo.UseShellExecute = false;
                //p.StartInfo.Arguments = @"/c echo off > fff1.txt";
                p.StartInfo.Arguments = @"/c ng build";
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;

                p.Start();

                p.Exited += new EventHandler(myProcess_Exited);

                var err = p.StandardError.ReadToEnd();
                var msg = p.StandardOutput.ReadToEnd();

                Console.WriteLine("error", msg, err);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error");
            }

        }
        private void myProcess_Exited(object sender, System.EventArgs e)
        {
            Console.WriteLine("Exit time:    {0}\r\n" +
                "Exit code:    {1}\r\nElapsed time: {2}");
        }

推荐答案

ng.cmd 位于 C:\ Users \<用户名> \ AppData \ Roaming \ npm ,但是默认的应用程序池标识没有访问该文件夹的权限.

ng.cmd is located in C:\Users\<user name>\AppData\Roaming\npm but the default application pool identity has no permissions to access that folder.

授予NTFS对应用程序池标识的读取权限,并确保该文件夹包含在 PATH 环境系统变量中.

Grant NTFS read permissions to application pool identity and make sure that folder is included in the PATH environment system variable.

DefaultAppPool的默认应用程序池标识为 IIS APPPOOL \ DefaultAppPool ..您需要向该帐户授予权限.

The default app pool identity for DefaultAppPool is IIS APPPOOL\DefaultAppPool.. You need to grant permissions to this account.

  1. 打开Windows资源管理器
  2. 转到 C:\ Users \<用户名> \ AppData \ Roaming
  3. 右键单击 npm
  4. 选择属性.
  5. 选择"安全性"标签
  6. 点击 edit 按钮
  7. 单击添加按钮
  8. 在文本框中输入 IIS APPPOOL \ DefaultAppPool
  9. 点击确定按钮
  10. 确保检查 Read and Execute List Folder and Content Read 权限.
  11. 点击确定
  12. 点击确定
  1. Open Windows Explorer
  2. Go to C:\Users\<user name>\AppData\Roaming
  3. Right click on npm
  4. Select Properties.
  5. Select Security tab
  6. Click on edit button
  7. Click on addbutton
  8. Enter IIS APPPOOL\DefaultAppPool on the text box
  9. Click Ok button
  10. Ensure Read and Execute, List Folder and Content and Read Permissions are checked.
  11. Click Ok
  12. Click Ok

这篇关于无法使用cmd.exe在iis托管的asp.net Web应用程序中执行命令ng build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆