博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
把.net中ViewState的隐藏内容调整到网站的底部
阅读量:4693 次
发布时间:2019-06-09

本文共 1315 字,大约阅读时间需要 4 分钟。

.net的网站,Viewstate视图状态的隐藏内容有时候会很长,影响到搜索引擎的收录问题,下面这段代码通过重写System.Web.UI.Page中的Render方法,来实现把ViewState调整到网站的底部。

View Code
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; using System.Web.UI; using System.Threading; using System.Text.RegularExpressions; using System.Text; ///  /// 重写System.Web.UI.Page里面的Render方法,实现把viewstate的位置放到网站底部 ///  namespace BLL {
public class ViewstateMethod : System.Web.UI.Page {
#region 重写Render方法,调viewstate位置并输出 protected override void Render(HtmlTextWriter writer) {
StringBuilder sb = new StringBuilder(); System.IO.TextWriter tw = new System.IO.StringWriter(sb); HtmlTextWriter OriginalStream = new HtmlTextWriter(tw); base.Render(OriginalStream); string s = sb.ToString(); Regex regex = new Regex( "
\r\n
\r\n
", RegexOptions.IgnoreCase); Match m = regex.Match(s); if (m.Success) {
s = regex.Replace(s, String.Empty); s = s.Replace("", m.Groups[0] + Environment.NewLine + ""); } writer.Write(s); } #endregion } }

如果遇到不能用的情况,中间正则的那行可作修改。

使用页面直接继承这个类即可。

转载于:https://www.cnblogs.com/lear/archive/2012/03/01/2376215.html

你可能感兴趣的文章
9结构型模式之代理模式
查看>>
第二节 整型数据
查看>>
Python 序列
查看>>
Liferay的架构:缓存(第一部分)
查看>>
初识B/S结构编程技术
查看>>
方法、hadoop源码之JobQueueTaskScheduler-by小雨
查看>>
页面重构总结
查看>>
IO 函数
查看>>
Unity V3 初步使用 —— 为我的.NET项目从简单三层架构转到IOC做准备
查看>>
JSP页面间传递参数
查看>>
VSNETcodePrint 2005 & SQL ServerPrint 2005
查看>>
java数组基本操作
查看>>
String的indexOf()用于获取字符串中某个子字符串的位置
查看>>
shell 脚本运算符
查看>>
又一道软通动力7K月薪面试题——银行业务调度系统
查看>>
Matlab画图-非常具体,非常全面
查看>>
ReactJS入门
查看>>
linux网站配置文件.htaccess伪静态转换到IIS web.config中
查看>>
CodeForces 1B
查看>>
win10应用UserControl
查看>>