views:

110

answers:

1

I have an ASP.NET web service which will create a text file in a path which is being passed as a parameter to the method.

 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();
 }

Now I am passing a folder in the network as the parameter and calling the method

  CreateFile(@"\\192.168.0.40\\labels\\test.txt");

When running the code from the Visual studio IDE,the file is getting created in the path.But when i published this and deployed as a virtual directoty,Its throwing me some error like

   "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)

I have in my web.config.My machine is running in XP and the other is in Windows Server 2003 . I have set WRITE permission to "Anyone" for that folder

Any idea to solve this ?? Thanks in advance

+1  A: 

Your web application is running under the local aspnet user account, which does not have access to the resource on the network. If you have application pools in your IIS version, you have to make the application pool user a domain user that has access to the network resource. If you do not have application pools, you change the user for the web in the processModel element of the web.config.

Tom Cabanski