IIS WEB程序如何访问共享目录

写好的ASP.NET MVC程序,在本机可以访问共享目录

 WebClient myWebClient = new WebClient();
                if (!string.IsNullOrEmpty(pic1))
                {
                    myWebClient.DownloadFile(new Uri(OrderingPlatformProductPicUrl + pic1), "//192.168.1.2/Ashare/" + productCode + "z.jpg");//
                }

但是发布到IIS7后,就发现报访问被拒绝的错误了(注IIS与共享目录是两台不同的服务器)

解决办法

1.在共享目录的电脑新增用户ShareOne,密码123,指定ShareOne用户可以访问共享目录

2.在IIS服务器新增用户ShareOne,密码123

3.在IIS虚拟目录的基本设置中,设置连接为

4.配置网站的WebConfig,支持WEB特定用户访问

  <system.web>
 <identity impersonate="true" userName="ShareOne" password="123" />
  </system.web>

5.大功告成

原文地址:https://www.cnblogs.com/berlin/p/5493111.html