2

XmlDataSource这样使用:

<asp:XmlDataSource ID="xmlDataSource1" runat="Server" DataFile="https://myurl.xml" ></asp:XmlDataSource>

作为我rotater控制的数据源。


但我一直得到以下异常:

https://myurl.xml不是有效的虚拟路径。

虽然我在外部尝试了链接并且有一个 xml 文件

4

1 回答 1

5

忽略我之前的回答。显然,XmlDataSource不喜欢 https URL DataFile

// works
xmlDataSource1.DataFile = "http://code.google.com/feeds/p/google-code-prettify/svnchanges/basic";
// does not work
xmlDataSource1.DataFile = "https://code.google.com/feeds/p/google-code-prettify/svnchanges/basic";

编写几行额外的代码以从 https 源下载 XML,例如:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://code.google.com/feeds/p/google-code-prettify/svnchanges/basic");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream()); 
string str = reader.ReadToEnd();
// save it or set it as the .Data property of XmlDataSource
于 2012-03-05T15:06:29.433 回答