我已经将一个网站部署到 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