简体   繁体   English

IIS - 403 Forbidden:访问通过 IIS 7.0 发布的文件夹时访问被拒绝

[英]IIS - 403 Forbidden: Access is denied when accessing a folder published through IIS 7.0

We published a folder through IIS 7.0 as below and put some files in it我们通过IIS 7.0发布了一个文件夹如下,里面放了一些文件

https://www.example.net/mydocs

If we access the files as below through browser we are able to see it如果我们通过浏览器访问下面的文件,我们就能看到它

https://www.example.net/mydocs/client.xml
https://www.example.net/mydocs/log.jpg

etc.. ETC..

Now we need to write a pgm to download and upload files to this folder and we coded as below现在我们需要编写一个 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);
            }

But it throwing and error at serverResponse = serverRequest.GetResponse();但它在serverResponse = serverRequest.GetResponse();处抛出错误

The error is The remote server returned an error: (403) Forbidden.错误是远程服务器返回错误:(403)禁止访问。

Also if we try to access另外,如果我们尝试访问

https://www.example.net/mydocs

through browser we are getting the error通过浏览器我们收到错误

403 - Forbidden: Access is denied. 403 - 禁止访问:访问被拒绝。 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 发布的文件夹时

You need to Allow Directory Browsing from IIS.您需要允许从 IIS 进行目录浏览。 Follow below steps to allow Directory Browsing.按照以下步骤允许目录浏览。

  • Open IIS .打开IIS
  • Select Your website from Left Pane.从左窗格中选择您的网站。
  • Double click Directory Browsing from Right Pane/Center Pane.双击右侧窗格/中心窗格中的Directory Browsing
  • In Right Pane under Actions Click Enable .在右窗格中的Actions下单击Enable

In my experience it ended up being missing windows features installed.根据我的经验,它最终会丢失安装的 Windows 功能。

I can't exactly point out which features are missing as I got tired of it and installed most of them, but that for sure solved my problem (and enabling directory browsing did not).我无法准确指出缺少哪些功能,因为我厌倦了它并安装了其中的大部分功能,但这肯定解决了我的问题(并且启用目录浏览没有)。

You Need to Enable the Directory Browsing in IIS or else you can access only files by giving full path up to the file.您需要在 IIS 中启用目录浏览,否则您只能通过提供文件的完整路径来访问文件。 Refer this link will show how 请参阅此链接将显示如何

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM