【发布时间】:2017-07-03 15:06:05
【问题描述】:
我们通过 IIS 7.0 发布了一个文件夹,如下所示,并在其中放入了一些文件
https://www.example.net/mydocs
如果我们通过浏览器访问以下文件,我们可以看到它
https://www.example.net/mydocs/client.xml
https://www.example.net/mydocs/log.jpg
等等。
现在我们需要编写一个pgm来下载和上传文件到这个文件夹,我们编码如下
WebClient webClient = new WebClient();
string webAddress = null;
try
{
webAddress = @"https://www.example.net/mydocs";
webClient.UseDefaultCredentials = true;
webClient.Credentials = CredentialCache.DefaultCredentials;
WebRequest serverRequest = WebRequest.Create(webAddress);
WebResponse serverResponse;
serverResponse = serverRequest.GetResponse();
serverResponse.Close();
webClient.UploadFile(webAddress + @"1.xml", "PUT", @"C:\d\1.xml");
webClient.Dispose();
webClient = null;
}
catch (Exception error)
{
MessageBox.Show(error.Message);
}
但它在serverResponse = serverRequest.GetResponse(); 处抛出错误
错误是远程服务器返回错误:(403) Forbidden。
如果我们尝试访问
https://www.example.net/mydocs
通过浏览器我们得到了错误
403 - 禁止:访问被拒绝。您无权查看 此目录或页面使用您提供的凭据。什么时候 访问通过iis发布的文件夹
【问题讨论】:
-
您需要允许从 IIS 进行目录浏览。