-2
WebRequest mywebReq ;
WebResponse mywebResp ;
StreamReader sr ;
string strHTML ;
StreamWriter sw;
mywebReq = WebRequest.Create("http://domain/sitecore/content/test/page10.aspx");
mywebResp = mywebReq.GetResponse();
sr = new StreamReader(mywebResp.GetResponseStream());
strHTML = sr.ReadToEnd();
sw = File.CreateText(Server.MapPath("hello.html"));
sw.WriteLine(strHTML);
sw.Close();

你好 ,

我想将 sitecore .aspx 页面保存到本地磁盘上的 html 文件中,但出现异常。但是,如果我使用任何其他网页示例(google.com),它就可以正常工作。

例外:

System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
   at System.Net.WebClient.DownloadFile(Uri address, String fileName)
   at System.Net.WebClient.DownloadFile(String address, String fileName)
   at BlueDiamond.addmodule.btnSubmit(Object sender, EventArgs e) in  c:\inetpub\wwwroot\STGLocal\Website\addmodule.aspx.cs:line 97

内部异常:

任何帮助。提前致谢

4

2 回答 2

2

我猜您还没有在 Sitecore 中发布您的页面。如果您浏览到 domain/sitecore/content/test/page10.aspx?sc_mode=normal,您会看到该页面吗?如果不发布页面(以及测试页面、模板和所有其他依赖项)。

于 2013-11-08T09:14:47.847 回答
0

Jim,您可以尝试 HTMLAgility 包中的一些示例。它包含在 sitecore 中,可以完美地处理这种情况。这是一个例子: http ://blog.abodit.com/2010/03/a-simple-web-crawler-in-c-using-htmlagilitypack/

于 2013-11-08T06:13:26.903 回答