WebRequest.GetResponse()抛出错误401:未经授权 [英] WebRequest.GetResponse() is throwing error 401: Unauthorized
问题描述
我在哪里,我想输出previously访问过的地方aspx页面的HTML ASP.NET应用程序(它的一个报告,我想保存它的一个静态的HTML副本的压缩文件)。我存储在本地页面的URI有:
I have an ASP.NET application where I'm trying to output the previously-visited local aspx page to html (its a report and I want to store a static html copy of it as an archive). I store the uri of the local page with:
Session["SummaryURI"] = Request.Url.AbsoluteUri;
和然后在下一页I与检索它
and then in the next page I retrieve it with:
string url = Session["SummaryURI"].ToString();
url = url.Replace("static=false", "static=true");
//MessageLabel.Text = url;
//CREATE THE NEW FILE
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse();
部分 req.GetResponse()
是我得到我的错误( 401未授权
)
我需要在IIS中配置的东西,使这个?
Do I need to configure something in IIS to allow this?
我是否需要修改文件权限或东西吗?
Do I need to edit file permissions or something?
感谢您的帮助。
顺便说一句这工作正常我本地IIS,但不是我的测试服务器上。
By the way this works fine on my local IIS but not on my test server.
推荐答案
截至目前我没有访问IIS设置,所以我不能让匿名身份验证
这是非常可能的,为什么Cybernate的回答并没有为我工作。然而,我却发现了工作更简单的方法。而不是使用的的WebRequest
我发现我可以做使用Server.Execute
同样的事情。下面是我的新的解决方案:
As of right now I don't have access to the IIS settings so I couldn't enable Anonymous Authentication
which is very possible why Cybernate's answer was not working for me. I did find however a simpler method that worked. Instead of using a WebRequest
I found that I could do the same thing with Server.Execute
. Below is my new solution:
string strHTML = String.Empty;
using (var sw = new StringWriter())
{
Server.Execute([path-to-local-aspx], sw);
strHTML = sw.ToString();
}
string relativeReportPath = [relative-path-to-new-html-file];
using (StreamWriter writer = File.CreateText(Server.MapPath(relativeReportPath)))
{
writer.WriteLine(strHTML);
MessageLabel.Text = "Your report is ready. Click Close to close the window.";
}
这篇关于WebRequest.GetResponse()抛出错误401:未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!