我們通過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