Permission issue when webservice deployed as virtual directory.Works in VS IDE

Posted by Shyju on Stack Overflow See other posts from Stack Overflow or by Shyju
Published on 2010-04-27T12:36:09Z Indexed on 2010/04/27 12:43 UTC
Read the original article Hit count: 252

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

Any idea to solve this ?? Thanks in advance

© Stack Overflow or respective owner

Related posts about permission-denied

Related posts about ASP.NET