0

Image Compression: We have 2 different servers on the same network Server A has document folder where all the documents are saved. Server B has the code which tries to access the documents on Server A and then compress it.

Error: Access to path denied My path --> \\ServerName\E$\ClientFiles\SHAH\SHAH_103696_20220531160805_2600.jpg

The folder and all its contents have been given full permissions. I also added Network Service and gave full permissions

public void ImageCompressionStream(ShahImages fileImage)
{          
    try
    {                
        using (WebClient webClient = new WebClient())
        {
            byte[] data = webClient.DownloadData(fileImage.filePath);

            using (MemoryStream mem = new MemoryStream(data))
            {
                using (var yourImage = Image.FromStream(mem))
                {
                     yourImage.Save(fileImage.filePath, ImageFormat.Jpeg);
                }
            }

        }
    }
    catch (Exception ex)
    {
         
    }
}
  • Under what user is the app pool running in IIS? Is the user a domain user, or `NETWORK SERVICE` or `SYSTEM`? Are both machines joined to the same domain? – Charlieface Jun 08 '22 at 21:01
  • app pool running on NETWORK SERVICE. Both machines are not joined to same domain. – user2147447 Jun 08 '22 at 21:23
  • `NETWORK SERVICE` will authenticate on the network as the machine itself. If they are not joined to the same domain, how would they trust each other? Either you set up a domain trust relationship between the two domains, or you join them to the same domain, or you do the equivalent `net use` with a user and password for the remote machine – Charlieface Jun 08 '22 at 22:18
  • Every resource access requires an account with proper permissions. You might try to grab a Windows administration book to study some backgrounds, but Network Service account on one machine isn't the Network Service on another machine, so when you described "The folder and all its contents have been given full permissions. I also added Network Service and gave full permissions" you should realize that didn't work at all. Like the other comment indicated without creating a domain and enroll the machines, things won't work out easily. – Lex Li Jun 08 '22 at 23:35
  • You can try the solution in this link: [https://stackoverflow.com/questions/28360275/iis-access-to-the-path-is-denied](https://stackoverflow.com/questions/28360275/iis-access-to-the-path-is-denied). – samwu Jun 09 '22 at 06:52
  • @samwu, I gave all the permissions that were listed in that thread. it did not help. – user2147447 Jun 10 '22 at 02:49
  • @Charlieface, can you give any link or elaborate on " net use with a user and password for the remote machine " ? – user2147447 Jun 10 '22 at 02:50
  • https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/gg651155(v=ws.11) I'm not sure what the equivalent C# code is, but maybe you could just do that via `Process.Start`. If you use `/persistent` then you only need to run it once anyway – Charlieface Jun 10 '22 at 09:07

0 Answers0