我有一个中等信任级别的主机,即时通讯使用imageresizer nuget包为我的图像进程。所以当我试图使用ImageBuilder.Build我得到这个错误:Threading.Timer文件创建问题
Access to the path '(path)' is denied.
System.UnauthorizedAccessException: Access to the path '(path)' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at ImageResizer.ImageBuilder.BuildJob(ImageJob job)
at ImageResizer.ImageBuilder.Build(ImageJob job)
at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource, Boolean addFileExtension)
at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource)
at _10oy.UI.Web.Imager.Models.Downloader.SaveAndSetDimension(String path, Int32 width, Int32 height)
btw:(路径)的编辑我。
我研究错误,但我没有找到任何有效的结果。
这里是我的代码(我称其为threading.timer,它可以是问题?)
public void SaveAndSetDimension(string path, int width, int height)
{
try
{
ImageBuilder.Current.Build(_MainStream, path, new ResizeSettings() { MaxWidth = width, MaxHeight = height }, false);
}
catch (Exception ex)
{
Results.Failed++;
DAL.Classes.Log.Write(
message: ex.Message,
innerexcepition: ex.InnerException != null ? ex.InnerException.ToString() : ex.ToString(),
user: "Saver",
interfaces: 4 //Imager
);
}
}
我试图常规文件在操作创建
public ContentResult CreateFile()
{
System.IO.File.Create(Server.MapPath("~/myfile.txt"));
return Content("File Created");
}
及其工作。
谢谢。
编辑:当我把它叫做正常动作时它的工作很好,但是当在定时器中调用时我得到了这个错误。
您的手动CreateFile()方法可以写入ImageResizer试图写入的* same *路径吗? – christofr
是的,我尝试过。它的工作。 – alim
嗯,棘手。 ImageResizer可能将工作交付给需要更多特权的插件。你使用任何插件? – christofr