2012-04-12 30 views
0

我正在研究ASP.NET中的iframe。下面是iframe中HTMlL代码:从C#中的iframe获取HTML源代码#

<iframe id="mainiFrame" name="mainiFrame" scrolling="auto" frameborder="2" 
      height="400px" width="500px"    
      src="" 
      runat="server"></iframe> 

我能够设置iframe的来源:

protected void Button1_Click(object sender, EventArgs e) 
    { 
     mainiFrame.Attributes["src"] = "http://roboticsindia.com"; 
    } 

我要如何从iFrame的HTML源代码?

问候, 阿尼尔

+0

http://stackoverflow.com/questions/168236/how-can-i-access-an-iframe-from-the-codebehind-file-in -asp-net – Flot2011 2012-04-12 08:56:15

回答

0

我不知道,如果一个iFrame的HTML源代码是一个属性或没有,但你可以做到这一点,像这样。

System.Net.WebClient wc = new System.Net.WebClient(); 
String s = wc.DownloadString(mainiFrame.Attributes["src"]); 
+0

工作正常,但在尝试访问'https:'页面时投掷了401错误 – 2012-04-12 12:48:16

+0

如果您的ht tps页面需要使用类似basic或challenge的登录,那么它可能会导致401,WebClient将不会使用与iFrame相同的会话。 我试过它在一个不需要登录的https页面上,它很好。 – Matt 2012-04-13 09:30:09

0

如果网页“http://roboticsindia.com”是不是在你的项目 你可以尝试Web客户端来获取HTML内容...

0

我们可以通过设置HTML I帧如下属性“测试帧”是I帧的编号

this.testframe.Attributes["src"] = "http://examples.com"; 
+0

Bhaskarreddy Mule,你看过这个问题吗? '我可以设置iframe的来源:'&'我如何从iFrame获取HTML源代码?' – 2012-04-12 11:58:55