gpt4 book ai didi

c# - 无法使用 inkscape 从 ASP.NET 生成文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:13 26 4
gpt4 key购买 nike

我的本​​地计算机上有一个 ASP.NET 应用程序可以运行。此应用程序采用 SVG 文件并使用 inkscape 从中创建 PNG。我试图将该应用程序迁移到我的生产服务器。奇怪的是,png 创建不起作用。真正奇怪的是,也没有抛出 Exception。我已经获取了正在创建的命令行参数,并将它们复制并粘贴到命令行环境中,它们可以正常工作。例如,这是一行:

inkscape.exe -f "C:\inetpub\wwwroot\MyTest\sample.svg" -e "C:\inetpub\wwwroot\MyTest\sample.png"

我认为这很简单,所以我将代码提取到示例 Web 项目中。该项目只是将 .svg 转换为 .png。再一次,它在我的本地环境中有效,但在生产环境中无效。这是代码:

protected void executeButton_Click(object sender, EventArgs e)
{
try
{
string sourceFile = Server.MapPath("svg") + "\\" + ConfigurationManager.AppSettings["sourceFile"];
string targetFile = Server.MapPath("png") + "\\" + ConfigurationManager.AppSettings["targetFile"];

string args = "-f \"" + sourceFile + "\" -e \"" + targetFile + "\" -w100 -h40";
string inkscape = ConfigurationManager.AppSettings["inkscapeExe"];

// Generate the png via inkscape
ProcessStartInfo inkscapeInfo = new ProcessStartInfo(inkscape, args);
Process inkscape = Process.Start(inkscapeInfo);
inkscape.WaitForExit(5000);

runLiteral.Text = "Success!<br />" + args;
}
catch (Exception ex)
{
runLiteral.Text = ex.GetType().FullName + "<br />" + ex.Message + "<br />" + ex.StackTrace;
}
}

谁能告诉我我做错了什么?

谢谢!

最佳答案

需要检查的几件事:

  • 确保 Web 应用程序的应用程序池标识(在 IIS 中找到,通常是 NetworkService)具有执行 inkscape.exe 的权限
  • 如果没问题,请检查以确保该目录向您将 PNG 写入的目录(“C:\inetpub\wwwroot\MyTest”)上的 apppool 身份授予修改权限
  • 或者,您可以使用模拟在特定 Windows 帐户下运行可执行文件。

关于c# - 无法使用 inkscape 从 ASP.NET 生成文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3909505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com