我正在使用 AppPool 标识从 IIS 站点运行 soffice.exe,以将 docx 转换为 pdf。
不知何故,它尝试在 C:/Windows/LibreOffice 中创建文件,这会导致访问错误。 什么可能导致这种行为?
这是代码部分:
string libreOfficePath = @"C:\Program Files\LibreOffice\program\soffice.exe";
string docxPath = @"D:\docs\abc.docx";
string pdfOutputPath = @"D:\docs\out";
string logPath = @"D:\docs\logs";
string arguments = "--headless --convert-to pdf " + docxPath + " --outdir " + pdfOutputPath;
var startInfo = new ProcessStartInfo
{
FileName = libreOfficePath,
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = @"C:\Program Files\LibreOffice\program"
};
如果我将应用程序池标识设置为 localsystem,该命令将完成工作并创建 pdf。
如果我设置为应用程序池身份,该进程会尝试在 C:/Windows/LibreOffice 中创建临时文件,这显然会失败。
这是它得到的命令行:
"C:\Program Files\LibreOffice\program\soffice.exe" "--headless" "--convert-to" "pdf" "D:\docs\abc.docx" "--outdir" "D:\docs\out" "-env:OOO_CWD=2C:\\Program Files\\LibreOffice\\program"
经过数百次尝试后,使用以下命令指定文件夹:
-env:UserInstallation=
解决了问题。