asp.net viewstate asp.net 去除viewstate
人气:0想了解asp.net 去除viewstate的相关内容吗,在本文为您仔细讲解asp.net viewstate的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:asp.net,viewstate,下面大家一起来学习吧。
看下这段代码:生成了这么多的一段东西,这段东西对seo一点好处也没有。而我要做的就是去掉它,但有一点,去掉但不能让它原来的控件和内容都发生变化,比如说不能使用等等。所以我要做的仅仅是用另一种方式去保存这些数据。这是一段用base64编码的数据而并不是加密,我很好奇到底放了些什么东西在这里面。下面我开始破解这段代码。代码如下:
复制代码 代码如下:
string str = "/wEPDwUKLTY4MTg1OTU4Nw9kFgJmD2QWAgIED2QWAgIDD2QWEGYPFgIeBFRleHQFDOeOqeWFt+WIhuexu2QCAQ8WAh4LXyFJdGVtQ291bnQCGBYwZg9kFgJmDxUCAzc4NQ7ovabns7vliJcgQ2Fyc2QCAQ9kFgJmDxUCAzgwMQ/oiLnns7vliJcgQm9hdHNkAgIPZBYCZg8VAgM4MDkT6aOe5py657O75YiXIFBsYW5lc2QCAw9kFgJmDxUCAzgxMRDpo57nop/ns7vliJcgVUZPZAIED2QWAmYPFQIDODEyGOebiuaZuuezu+WIlyBFZHVjYXRpb25hbGQCBQ9kFgJmDxUCAzgxMxXlqbTlhL/ns7vliJcgQmFieSBzZXRkAgYPZBYCZg8VAgM4MTQU5Yqo5ryr57O75YiXIENhcnRvb25kAgcPZBYCZg8VAgM4MTUU5rOh5rOh57O75YiXIEJ1YmJsZXNkAggPZBYCZg8VAgM4MTYa6K6+5pa957O75YiXIEVzdGFibGlzaG1lbnRkAgkPZBYCZg8VAgM4MTcT6L+Q5Yqo57O75YiXIFNwb3J0c2QCCg9kFgJmDxUCAzgxOBnmraboo4Xns7vliJcgTWlsaXRhcnkgc2V0ZAILD2QWAmYPFQIDODE5FuijhemlsOezu+WIlyBPcm5hbWVudHNkAgwPZBYCZg8VAgM4MjAa6YCa6K6v57O75YiXIENvbW11bmljYXRpb25kAg0PZBYCZg8VAgM4MjEU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c3QkY3RsMDMkY2J4SWQFJ2N0bDAwJG1pZGRsZWNvbnRlbnQkcnB0TGlzdCRjdGwwNCRjYnhJZJUbUL345MMI0kzOqwpteqbHQo0f";
byte[] barray;
barray = Convert.FromBase64String(str);
UTF8Encoding utf8 = new UTF8Encoding();
Response.Write(utf8.GetString(barray));
结果如下:
复制代码 代码如下:
�
-681859587dfdddfText 玩具分类d _!ItemCount0fdf785车系列 Carsddf801船系列 Boatsddf809飞机系列 Planesddf811飞碟系列 UFOddf812益智系列 Educationalddf813婴儿系列 Baby setddf814动漫系列 Cartoonddf815泡泡系列 Bubblesddf816设施系列 Establishmentd df817运动系列 Sportsd
df818武装系列 Military setd df819装饰系列 Ornamentsd df820通讯系列 Communicationd
df821乐器系列 Musicalddf822水机系列 Water gameddf823风扇系列 Fanddf824工具系列 Toolsddf825动物系列 Animalsddf826相机系列 Cameraddf827消防系列 Fire Engineddf828工程系列 Engineeringddf829自装玩具 DIYddf830文具系列 Stationeryddf831其他玩具 Other Toysd NavigateUrl>list.aspx?id=&brand=&num=&order=0&key_n=&key_p_max=&key_p_min=dd>list.aspx?id=&brand=&num=5&order=&key_n=&key_p_max=&key_p_min=dd?list.aspx?id=&brand=&num=10&order=&key_n=&key_p_max=&key_p_min=dd?list.aspx?id=&brand=&num=15&order=&key_n=&key_p_max=&key_p_min=dd
fd131680./upload/20090326014840585.jpgd131680电动军事艇加军人d CommandName131680dd131680254dozdd131694./upload/20090326014840366.jpgd131694 游泳镜d131694dd131694518dozdd131686./upload/20090326014841257.jpgd131696 游泳镜d131696dd131696524dozdd131700./upload/20090326014841892.jpgd131700 游泳镜d131700dd131700516dozd CurrentPageIndex Recordcount�)PageSizedd__ControlsRequirePostBackKey__'ctl00$middlecontent$rptList$ctl00$cbxId'ctl00$middlecontent$rptList$ctl01$cbxId'ctl00$middlecontent$rptList$ctl02$cbxId'ctl00$middlecontent$rptList$ctl03$cbxId'ctl00$middlecontent$rptList$ctl04$cbxId�P�����LΫ
这个大家可以在http://gallery.toysgogo.com/list.aspx这个页面中看到。
ViewState 在 Page.SavePageStateToPersistenceMedium 方法中被保存, 回发时,在 Page.LoadPageStateFromPersistanceMedium 方法中被恢复。 这是我在看“木野狐”翻译的一篇文章中看到的,那么我们可以将其存到session中去,代码如下,来自网络,自做简单修改:
复制代码 代码如下:
protected LosFormatter losFormatter = new LosFormatter();
protected override object LoadPageStateFromPersistenceMedium()
{
string key = Request.RawUrl + "__viewstate";
if (Session[key] != null)
{
System.IO.MemoryStream stream = (System.IO.MemoryStream)Session[key];
stream.Seek(0, System.IO.SeekOrigin.Begin);
return losFormatter.Deserialize(stream);
}
return null;
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
string key = Request.RawUrl + "__viewstate";
System.IO.MemoryStream stream = new System.IO.MemoryStream();
losFormatter.Serialize(stream, viewState);
stream.Flush();
Session[key] = stream;
}
那么看看现在的viewstate:
复制代码 代码如下:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id=" __VIEWSTATE" value="" />
到这一步,我们实现我们要用的功能,去除viewstate,同时保持原先页面的使用。
加载全部内容