我们通过IIS 7.0如下出版了一本文件夹时,访问被拒绝,并把一些文件进去403 - 禁止:访问通过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();
The error is The remote server returned an error: (403) Forbidden.
此外,如果我们试图访问
https://www.example.net/mydocs
通过浏览器,我们所得到的是错误
403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied. when accessing the folder published through iis
您需要允许从IIS进行目录浏览。 – Mairaj