I'm trying to take screenshots from a web server running on C#, IIS and Windows. Whenever I run the following code, the screenshot is not taken and I don't know the reason because nothing actually fails.
When I run the same code from a local console application it works. So I'm assuming it's something related to permissions but I can't find any docs related to this. The folder that has chrome has a Full Permission to the any user (at least while I'm testing).
Does anyone has any tip on it?
Here's the code I'm using:
var pathToBrowser = @"E:\sources\webapps\RapidResponse\Web Server\chromium\bin\chrome.exe";
var pathToScreenshotFile = Path.Combine(Path.GetTempPath(), $"{filename}.png");
var arguments = $@" --headless --hide-scrollbars --disable-gpu --screenshot=""{pathToScreenshotFile}"" --window-size={1920},{874} https://google.com";
var psi = new ProcessStartInfo(pathToBrowser, arguments) { UseShellExecute = false, Verb = "runas" };
using (Process process = Process.Start(psi))
{
Thread.Sleep(1000);
var image = string.Empty;
var executionCount = 0;
while (image == string.Empty && executionCount < 5)
{
if (File.Exists(pathToScreenshotFile))
{
image = Convert.ToBase64String(File.ReadAllBytes(pathToScreenshotFile));
}
else
{
Thread.Sleep(1000);
}
}
return image;
}