メソッドにパラメーターとして渡されるパスにテキスト ファイルを作成する ASP.NET Web サービスがあります。
private void CreateFile(string path)
{
string strFileName = path;
StreamWriter sw = new StreamWriter(strFileName, true);
sw.WriteLine("");
sw.Write("Created at " + DateTime.Now.ToString());
sw.Close();
}
今、ネットワーク内のフォルダーをパラメーターとして渡し、メソッドを呼び出しています
CreateFile(@"\\192.168.0.40\\labels\\test.txt");
Visual Studio IDE からコードを実行すると、パスにファイルが作成されます。しかし、これを公開して仮想ディレクトリとして展開すると、次のようなエラーが発生します
"System.UnauthorizedAccessException: Access to the path '\\192.168.0.40\labels\test.txt' 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)
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)
私は私<identity impersonate="true"/>
の中に持っていweb.config
ます。私のマシンは XP で実行されており、もう 1 つは Windows Server 2003 で実行されています。そのフォルダーの書き込み権限を「すべてのユーザー」に設定しました。