【发布时间】:2014-06-07 06:13:57
【问题描述】:
我们有一种方法可以将图像保存为正确的格式,如下所示:
public static string SaveImageAsCorrectFormat(string tempFilePath, string newFileName, string destinationDirectoryPath)
{
using (Image image = new Bitmap(tempFilePath))// Exception : Parameter is not valid.
{
string extension = image.RawFormat.GetExtension();
string newAbsoluteFilePath = Path.Combine(destinationDirectoryPath, string.Format("{0}.{1}", newFileName, extension));
image.Save(newAbsoluteFilePath, image.RawFormat);
return newAbsoluteFilePath;
}
}
但在以下行中发生了异常:
//Parameter is not valid.
using (Image image = new Bitmap(tempFilePath))
我将其更改为以下但 Out of memory 发生了:
// Out of memory
using (Bitmap image = (Bitmap)Image.FromFile(tempFilePath))
图像大小为 10KB,10GB 内存可用。
有什么问题?
附注:
我在本地没有问题。但是当我在服务器上发布软件时,就会出现这个问题。
编辑:
我正在使用windows Server 2012 R2 和IIS 8.5.9600.16384。应用程序(网站)可以完全控制 IIS_IUSRS 和 IUSR。
我认为问题与权限无关,因为我可以使用以下代码打开文件:
using (FileStream fileStream = File.Open(tempFilePath, FileMode.Open)) // OK
using (Image image = new Bitmap(fileStream))// Exception : Parameter is not valid.
解决方案:
我将网站application pool identity 更改为Local System 现在可以了,可以更改应用程序池身份还是安全漏洞?
【问题讨论】:
-
好吧,大概是 'tempFilePath' 中的文件夹不存在,或者如果它确实存在,您无权访问它
-
@MitchWheat:
tempFilePath中有一些目录,是软件创建的。如何查看权限?
标签: c# asp.net-mvc exception bitmap