WebServiceが仮想ディレクトリとして展開した場合の許可問題。 VS IDEで動作します

StackOverflow https://stackoverflow.com/questions/2721163

質問

メソッドのパラメーターとして渡されているパスにテキストファイルを作成する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で実行されています。そのフォルダーの「誰でも」に書き込み許可を設定しました。

役に立ちましたか?

解決

Webアプリケーションは、ネットワーク上のリソースにアクセスできないローカルASPNETユーザーアカウントの下で実行されています。 IISバージョンにアプリケーションプールがある場合は、アプリケーションプールユーザーをネットワークリソースにアクセスできるドメインユーザーにする必要があります。アプリケーションプールがない場合は、ユーザーをWebのユーザーを変更します。 ProcessModel web.configの要素。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top