【发布时间】:2014-04-17 15:03:43
【问题描述】:
IIS 8、ASP.NET MVC 4、.NET 4.5
private static string SaveProfilePicFile(UserProfileViewModel model)
{
var tempFilename = Path.GetTempFileName();
model.ProfilePic.Profile.UploadedFile.SaveAs(tempFilename);
var staticContentFilename = Helpers.GetStaticContentFilename(
StaticContentType.Avatar, model.ProfilePic.Profile.UserId);
var destinationFilename = Path.Combine(
ConfigurationManager.AppSettings["StaticContentPath"],
"profile",
staticContentFilename);
if (File.Exists(destinationFilename))
File.Delete(destinationFilename);
if (!HasJpegHeader(tempFilename)) // convert temp file into JPG
{
using (var image = new Bitmap(tempFilename))
image.Save(destinationFilename, ImageFormat.Jpeg);
File.Delete(tempFilename);
}
else
{
File.Move(tempFilename, destinationFilename);
}
return staticContentFilename;
}
我对代码审查不感兴趣,我知道事情可以做得更好。现在我遇到了一个不寻常的问题。 StaticContentPath 指向 c:\inetpub\wwwroot\static.domain.com,它由不同的应用程序池提供服务,该池被配置为禁用脚本并缓存更重的内容。如果我手动将文件放在静态内容文件夹中,它将正确提供。如果上面的代码(来自不同的应用程序池)在那里保存了一个文件,那么权限是非常不寻常的。我会附上截图。
“默认”文件是我手动粘贴的。它正确地从父文件夹继承了权限。哈希文件名是由上面的代码保存的,它没有正确继承权限。当我尝试访问该文件时,我从 IIS 收到一条非常基本的错误消息,其全部内容是“页面无法显示,因为发生了内部服务器错误”。没有样式,没有我习惯看到的 IIS 错误。如果我手动将读取权限添加到 IIS_IUSRS 帐户,一切都会按我的预期工作。
为什么会发生这种情况,我可以做些什么来缓解它,我的代码是否需要更新?
【问题讨论】:
-
也发布高级对话框的屏幕截图。
-
发布了其他截图。
标签: c# asp.net iis permissions ntfs