問題描述
當請求來自調度程序時,無法寫入 App_Data (Cannot write in App_Data when request is from scheduler)
Hello I have a page in an ASP.NET (website) project that writes a file to the App_Data folder. When I request the page from my browser everything works. When I perform this request from a cron-job scheduled job from my provider I get the following error
Could not find a part of the path 'C:\xxxxxxxxxxxxxxx\App_Data\Art_P00004.txt'.
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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at System.IO.File.CreateText(String path)
at AanbiedingProcessor.DoWriteFiles()
at TskSendAanbiedingen.DoWork()
Can anyone help me ?
The cron jon runs on another host/domain as the asp.net website. I assume it just makes a web request.
參考解法
方法 1:
This is likely to be a permissions issue.
Ensure the user account associated with the scheduled job has access to the App_Data folder.
Process Monitor can help to check exactly what is failing and why.
方法 2:
The problem was that the path did not exist.. :( The script called from the scheduler was different from the script (location) called within the browser. Excuse me for the confusion..
(by Julian de Wit、Richard、Julian de Wit)