为什么我无法使用从 ASP.Net 代码执行的 power shell 命令登录到 Azure?

Why am I not able to login to Azure using power shell commands that are being executed from ASP.Net code?

我已经创建了一个 ASP.Net Web 应用程序。从这个应用程序,我试图执行 power shell 命令来登录到 Azure。正在使用的命令是 'az login'。当我 运行 应用程序时,我得到了登录命令所期望的正确响应,该响应告诉我登录成功。但问题是,当我在 IIS 中托管相同的应用程序时,我没有得到预期的结果,而是得到一个空的响应,这表明存在一些问题。下面是我正在使用的代码:

        Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline();
        pipeline.Commands.AddScript("az login -u vtripathi@hsdyn.com -p ********");
        pipeline.Commands.Add("Out-String");
        var output = pipeline.Invoke();
        string result = output[0].ToString();

请指出可能存在的问题。

它与应用程序池标识有关。

将应用程序池标识更改为您的帐户而不是默认帐户,它应该可以工作。