在没有ViewState ASP.Net的情况下获取当前页面的HTML
发布时间:2020-12-16 00:02:44 所属栏目:asp.Net 来源:网络整理
导读:有什么方法可以让我获得当前页面的HTML.通过当前页面,我的意思是假设我正在使用Default.aspx,并希望通过在其上提供一个按钮来获取HTML. 怎么弄它. 解决方法 编辑以回应澄清要求 您可以覆盖页面的render方法以捕获服务器端的HTML源代码. protected override v
有什么方法可以让我获得当前页面的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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 使用ASP.NET MVC 2上传文件的最佳方法是什么
- 从ASP.NET Core连接到SQL Server的最佳实践?
- ASP.NET MVC 3中DropDownListFor的不显眼验证问题
- asp.net – 使用jquery的IE不能正常工作
- asp.net-core – 如何在EF Core 2.1.0中为Admin用户播种?
- asp.net – 查询字符串参数使我的应用程序面临风险?
- asp.net-mvc – ASP.NET MVC API或WCF API
- asp.net-mvc – 带网格的MVC3 Bootstrap tablular数据
- asp.net中强类型的会话
- asp.net-mvc – 使用Razor视图引擎 – 如何格式化十进制值以
推荐文章
站长推荐
- asp.net-mvc – MVC4 Razor – @ Html.DisplayFo
- 如何调试ASP.NET HTTPHandler
- asp.net-mvc – ASP MVC ChildActionOnly应该有路
- asp.net – LinkBut??ton CommandName和CommandA
- asp.net-mvc – 如果ModelState表示该字段无效,则
- Asp.net core中间件实现原理及用法解说
- asp.net-mvc – 在asp身份声明和会话数据之间进行
- asp.net – 解决方案:在使用User控件时,元素不是
- asp.net – 从多个表中计算数据
- asp.net – 多租户架构的实体框架 – 按租户ID过
热点阅读