因工作关系,网站首页要生成静态文件,而原来首页是asp文件,又不想在写其他的标签生成静态文件,于是偷个小懒,呵呵..上海网站制作
解决方法:把原来的index.asp改成别的文件,如Index_dwww.asp,这样别人就不能直接访问index.asp了,而每次调用数据库,耗费服务器。
生成的最终页面是静态的,减少了对服务器的压力 :)
代码如下:上海网站制作
<%
'输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function上海网站制作
'转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream上海网站制作
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function 上海网站制作
'ASP的随机函数,作者无情,来源 http://www.021-web.com.cn 转载请保留出处,谢谢
Function RndNumber(MaxNum,MinNum)
Randomize
RndNumber=int((MaxNum-MinNum+1)*rnd+MinNum)
RndNumber=RndNumber 上海网站制作
End Function
'生成函数
Function create_Index()
txtURL=("http://www.dwww.cn/?dwww="&RndNumber(30,10)&"") '加这个随机函数主要是为了防止服务器的缓存 上海网站制作
'txtURL 就是调用的网站的动态页面
sText = getHTTPPage(txtURL)
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="Index.html" '程序最终生成的页面 上海网站制作
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)上海网站制作
Set OpenFile=nothing
response.write "<h1>上海网站制作</h1>"
end Function
'调用代码
Call create_Index()
%> 上海网站制作