使用LibreOffice(soffice.exe)作为无法在IIS服务器上工作的代码背后的Process.Start() [英] Using LibreOffice(soffice.exe) as Process.Start() from Code behind not working on IIS server

查看:306
本文介绍了使用LibreOffice(soffice.exe)作为无法在IIS服务器上工作的代码背后的Process.Start()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LibreOffice作为将docx转换为pdf的命令行.我正在使用以下代码段.

I am using LibreOffice as command line for conversion of docx to pdf. I am using below code snippet.

    using (Process pdfprocess = new Process())
          {
            pdfprocess.StartInfo.UseShellExecute = true;
            pdfprocess.StartInfo.LoadUserProfile = true;
            pdfprocess.StartInfo.FileName = "soffice.exe";
            pdfprocess.StartInfo.Arguments = "-norestore -nofirststartwizard -headless -convert-to pdf C:\\test.docx";
            pdfprocess.StartInfo.WorkingDirectory = @"C:\Program Files\LibreOffice\program\";
            pdfprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            pdfprocess.Start();
            if (!pdfprocess.WaitForExit(1000 * 60 * 1)) {
                pdfprocess.Kill();
            }
            pdfprocess.Close();
        }

一切都可以在IISExpress或控制台应用程序下正常运行.当我尝试在IIS服务器下运行时,它不起作用.

Everything works fine under IISExpress or Console application. When I try to run under IIS server, it doesn't work.

我在 DefaultAppPool 下运行,并且我已授予 DefaultAppPool 访问LibreOffice目录的权限,但我无法获得结果.

I am running under DefaultAppPool and I have given permission to DefaultAppPool to access LibreOffice directory but I am not able to get result.

出于安全考虑,我不想将身份更改为 LocalSystem .

I don't want to change Identity to LocalSystem as security concerns.

如何在默认 ApplicationPoolIndentity 下使用Process.Start()运行 soffice.exe ?

How can I able to run soffice.exe using Process.Start() under default ApplicationPoolIndentity?

推荐答案

我遇到了同样的问题,而我只是

I had the same problem and I just found solution that worked for me. When I was executing conversion under CMD console everything was working fine. But soffice.exe executed under iis app didn't work.

尽管,应用程序池具有它自己的用户配置文件目录,看起来libreoffice无法在此处创建其文件.我所做的是我在iis www目录下创建了temp文件夹,并为其分配了apppool权限.然后,我使用其他参数传递了该位置,例如:"-env:UserInstallation = file:///C:/www/temp/libreoffice"

Although, application pool has it's own user profile directory it looks like libreoffice cannot create its files there. What I did is I created temp folder under iis www directory and gave it apppool permisions. Then I passed this location with other parameters like that: "-env:UserInstallation=file:///C:/www/temp/libreoffice"

这篇关于使用LibreOffice(soffice.exe)作为无法在IIS服务器上工作的代码背后的Process.Start()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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