有什么方法可以让我获得当前页面的HTML.通过当前页面,我的意思是假设我正在使用Default.aspx,并希望通过在其上提供一个按钮来获取HTML.
怎么弄它.
解决方法
编辑以回应澄清要求
您可以覆盖页面的render方法以捕获服务器端的HTML源代码.
protected override void Render(HtmlTextWriter writer) { // setup a TextWriter to capture the markup TextWriter tw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(tw); // render the markup into our surrogate TextWriter base.Render(htw); // get the captured markup as a string string pageSource = tw.ToString(); // render the markup into the output stream verbatim writer.Write(pageSource); // remove the viewstate field from the captured markup string viewStateRemoved = Regex.Replace(pageSource,"<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\".*?\" />","",RegexOptions.IgnoreCase); // the page source,without the viewstate field,is in viewStateRemoved // do what you like with it }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。