asp.net 生成靜態(tài)時(shí)的過濾viewstate的實(shí)現(xiàn)方法
更新時(shí)間:2009年03月05日 00:33:44 作者:
有時(shí)候我們在用asp.net生成靜態(tài)文件的時(shí)候,總會出現(xiàn)一些viewstate的字符,因?yàn)槭庆o態(tài)的不是aspx文件,所有沒必要留了,精簡代碼等原因,大家就需要看下面的方法了。
復(fù)制代碼 代碼如下:
public static string GetSourceTextByUrl(string url)
{
WebRequest request = WebRequest.Create(url);
request.Timeout = 200000;//20秒超時(shí)
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
string tempstr = sr.ReadToEnd();
Regex r1 = new Regex("<input type=\"hidden\" name=\"__EVENTTARGET\".*/>", RegexOptions.IgnoreCase);
Regex r2 = new Regex("<input type=\"hidden\" name=\"__EVENTARGUMENT\".*/>", RegexOptions.IgnoreCase);
Regex r3 = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\".*/>", RegexOptions.IgnoreCase);
//過濾<form>代碼
Regex r4 = new Regex("<form name=\"aspnetForm\".*id=\"aspnetForm\">", RegexOptions.IgnoreCase);
Regex r5 = new Regex("</form>");
tempstr = r1.Replace(tempstr, "");
tempstr = r2.Replace(tempstr, "");
tempstr = r3.Replace(tempstr, "");
tempstr = r4.Replace(tempstr, "");
tempstr = r5.Replace(tempstr, "");
return tempstr;
}
您可能感興趣的文章:
- asp.net 去除viewstate
- asp.net 禁用viewstate在web.config里
- asp.net viewstate 回發(fā)機(jī)制
- asp.net生成靜態(tài)后冗余代碼,去掉viewstate生成的代碼
- 使用正則Regex來移除網(wǎng)頁的EnableViewState實(shí)現(xiàn)思路及代碼
- 狀態(tài)保存機(jī)制之ViewState概述及應(yīng)用
- 禁止ViewState的3種解決方法
- viewstate和datatable動態(tài)錄入數(shù)據(jù)示例
- asp.net中ViewState的用法詳解
- ASP.NET中控件的EnableViewState屬性及徹底禁用
相關(guān)文章
asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時(shí)出現(xiàn)亂碼
asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時(shí)有時(shí)會出現(xiàn)亂碼,很是疑惑,不要走開接下來介紹解決方法,感興趣的朋友可以了解下2013-01-01
ASP.NET oledb連接Access數(shù)據(jù)庫的方法
這篇文章主要介紹了ASP.NET oledb連接Access數(shù)據(jù)庫的方法,需要的朋友可以參考下2015-01-01
Asp.net Core Jenkins Docker實(shí)現(xiàn)一鍵化部署的實(shí)現(xiàn)
這篇文章主要介紹了Asp.net Core Jenkins Docker實(shí)現(xiàn)一鍵化部署的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-01-01
詳解Asp.net Core 使用Redis存儲Session
本篇文章主要介紹了Asp.net Core 使用Redis存儲Session ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧。2016-12-12
異步 HttpContext.Current實(shí)現(xiàn)取值的方法(解決異步Application,Session,Cache.
在一個(gè)項(xiàng)目中,為了系統(tǒng)執(zhí)行效率更快,把一個(gè)經(jīng)常用到的數(shù)據(jù)庫表通過dataset放到Application中,發(fā)現(xiàn)在異步實(shí)現(xiàn)中每一次都會出現(xiàn)HttpContext.Current為null的異常,后來在網(wǎng)上查了好多資料,發(fā)現(xiàn)問這個(gè)問題的人多,回答的少2009-07-07

