C# 无法使用inkscape从ASP.NET生成文件
我有一个ASP.NET应用程序在我的本地机器上运行。该应用程序获取一个SVG文件,并使用inkscape从中创建一个PNG。我已尝试将该应用程序迁移到我的生产服务器。奇怪的是,png创建不起作用。真正奇怪的是,C# 无法使用inkscape从ASP.NET生成文件,c#,asp.net,svg,C#,Asp.net,Svg,我有一个ASP.NET应用程序在我的本地机器上运行。该应用程序获取一个SVG文件,并使用inkscape从中创建一个PNG。我已尝试将该应用程序迁移到我的生产服务器。奇怪的是,png创建不起作用。真正奇怪的是,异常也没有被抛出。我已经获取了正在创建和复制的命令行参数,并将它们粘贴到命令行环境中,它们可以正常工作。例如,下面是一行: inkscape.exe -f "C:\inetpub\wwwroot\MyTest\sample.svg" -e "C:\inetpub\wwwroot\MyTes
异常
也没有被抛出。我已经获取了正在创建和复制的命令行参数,并将它们粘贴到命令行环境中,它们可以正常工作。例如,下面是一行:
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;
}
}
protectedvoid executeButton\u单击(对象发送方,事件参数e)
{
尝试
{
字符串sourceFile=Server.MapPath(“svg”)+“\\”+ConfigurationManager.AppSettings[“sourceFile”];
字符串targetFile=Server.MapPath(“png”)+“\\”+ConfigurationManager.AppSettings[“targetFile”];
字符串args=“-f\”“+sourceFile+“\”-e\”“+targetFile+“\”-w100-h40”;
字符串inkscape=ConfigurationManager.AppSettings[“inkscapeExe”];
//通过inkscape生成png
ProcessStartInfo inkscapeInfo=新的ProcessStartInfo(inkscape,args);
Process inkscape=Process.Start(inkscapeInfo);
inkscape.WaitForExit(5000);
runLiteral.Text=“成功!
”+args;
}
捕获(例外情况除外)
{
runLiteral.Text=ex.GetType().FullName+“
”+ex.Message+“
”+ex.StackTrace;
}
}
有人能告诉我我做错了什么吗
谢谢大家! 需要检查的几件事:
- 确保web应用程序的应用程序池标识(在IIS中找到,通常是NetworkService)具有执行inkscape.exe的权限
- 如果没有问题,请检查以确保该目录在您将PNG写入到的目录(“C:\inetpub\wwwroot\MyTest”)上为apppool标识授予修改权限
- 或者,您可以使用模拟在特定Windows帐户下运行可执行文件