asp.net 生成静态时的过滤viewstate的实现方法
程序员文章站
2024-03-09 18:01:53
复制代码 代码如下:public static string getsourcetextbyurl(string url) { webrequest request = w...
复制代码 代码如下:
public static string getsourcetextbyurl(string url)
{
webrequest request = webrequest.create(url);
request.timeout = 200000;//20秒超时
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 Substitution 页面缓存而部分不缓存的实现方法
下一篇: 分段控制器