0

我已经将一个网站部署到 IIS(在本地机器上总是可以正常工作)并且发现当我运行我的一个例程时它失败并出现 401 未授权错误:

代码如下:

          string html = String.Empty;
            string CurrentURL = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Host + Request.Url.PathAndQuery;
            Byte[] sAttachment;

            using (WebClient client = new WebClient())
            {                    
                client.UseDefaultCredentials = true;

                _logger.Debug("Getting page content ready to fax...");
--> fails here: html = client.DownloadString(new Uri(CurrentURL));

                html = html.Replace("Add Recipient", "");
                html = html.Replace("Send Fax", "");
                html = html.Replace("Close", "");

                //make sure the destination fax number and recipient is in the html
                string toFaxDetailsHTML = "insertFaxDetails\">";
                toFaxDetailsHTML += "<label class=\"form-label col-md-2 text-right\">Fax: </label>" + FVM.ToFaxNumber + "<br/>";
                toFaxDetailsHTML += "<label class=\"form-label col-md-2 text-right\">To: </label>" + FVM.ToName + "<br/><br/>";
                html = html.Replace("insertFaxDetails\">", toFaxDetailsHTML);

                sAttachment = FVM.PdfSharpConvert(html);
                FVM.Attachment = sAttachment;
            }

任何帮助表示赞赏。

环境是 Windows 2008 R2 标准上的 IIS 7。使用 MVC 5 c# .NET 4.5.2

4

1 回答 1

0

IIS 创建一个名为“IUSR”的用户,以默认用户身份通过​​ IIS 访问文件。因此,“IUSR”对文件/文件夹具有适当的访问权限是很重要的。

因此,请按照以下步骤查看 IUSR 是否具有适当的访问权限:

Deploy Folder→Right Click→Properties→Security Tab

请确保 IUSR 在组或用户名列表中,如果否,请执行以下操作:

Click Edit→Add→Advanced→Find→Add IUSR.

※我使用的是日文版的寡妇,所以按钮名称可能会略有偏差

于 2017-10-25T04:34:43.983 回答