开发者

Is it ok to call Powershell from an ASP.Net process

开发者 https://www.devze.com 2023-01-15 13:18 出处:网络
Is there any problems wit开发者_如何学编程h creating a powershell runspace in an asp.net application and running commands?

Is there any problems wit开发者_如何学编程h creating a powershell runspace in an asp.net application and running commands?

I have a basic example working fine but I'm wondering if there are any pitfalls waiting for me.

I'm particularly wondering:

  • Is this an a light-weight inprocess operation or is it firing up another processes that could lead to unpredictable behaviour.


As long as you're not shelling out to powershell.exe explicitly, instead using Runspace and Pipeline objects directly, you can be assured it's fairly lightweight. Btw, if you are trying to interact with cmdlets through C#, only cmdlets that derive from PSCmdlet need a pipeline; ones that derive from Cmdlet directly can be called without a pipeline via the Invoke method. This is the most lightweight approach.


This should be OK. I've not done this in ASP.NET but I have hosted in-process with a desktop app. There is no external PowerShell process spun up unless you use background jobs. I think the Quest folks are also doing something like this with their Mobile Shell.


As I can see, others recommend using PowerShell. Well, personally, I would pay more attention. Why?

Each web request should be processed as quickly as possible and without any blocking. If the script contains commands that work with network, then there could be some timeouts (e.g. if the computer is not accessible). The processing thread will be blocked for all the time and can't serve any other web request. Then soon you might get Internal Server Error and similar responses.

Besides that (not proved) I suspect that PowerShell consumes more memory than similar code in C#.

I don't claim don't use Powershell, just pay attention ;)

0

精彩评论

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