您现在的位置:首页 >> 电脑技术 >> 网页设计 >> 内容

asp伪静态实现的代码

时间:2010/12/16 0:42:00 点击:

很简单的教程,献给喜欢SEO的朋友们。把http://www.***.cn/article.asp?logID=26   替换成http://www.***.cn/article.asp?/a26.html。不需要通过iis+ISAPI_Rewrite做基于IIS的url rewrite

一、数据库很简单使用ACCESS,Data.mdb建立一个表Article,三个字段:ID,Title,Content;自动编号、标题、文章内容。

二、Config.asp
ASP/Visual Basic代码

以下为引用的内容:
<%   
'数据库链接   
db="data.mdb"  
Set conn = Server.CreateObject("ADODB.Connection")   
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)   
conn.open connstr
    If Err Then  
        err.Clear   
        Set conn = Nothing  
        Response.Write "数据库连接出错,请检查连接字串。"  
        Response.End  
    End If
'定义新闻阅读界面的读取
Dim News_title,News_content   
Sub ReadNews()   
 set rs1=server.createobject("adodb.recordset")   
  sql1="select id,title,content from article where id="& ID   
rs1.open sql1,conn,3,3   
    News_title=rs1("title")   
    News_content=rs1("content")   
rs1.close   
set rs1=Nothing  
End Sub    
%>

三、Default.asp

以下为引用的内容:
ASP/Visual Basic代码
<!--#include file="config.asp"-->   
<ol>   
<%   
Set rs=server.CreateObject("adodb.recordset")   
sql="select * from Article"  
rs.open sql,conn,1,1   
do while not rs.eof   
%>   
<li><a href="article.asp?/<%=rs("id")%>.html"><%=left(trim(rs("title")),30)%></a></li>   
 


<%   
rs.movenext   
loop   
rs.close   
set rs=Nothing  
%>   
</ol>   

 


四、Article.asp


ASP/Visual Basic代码

以下为引用的内容:
<!--#include file="config.asp"-->   
<%   
id=request.QueryString("id")   
If id="" Then    
server_v40=Request.ServerVariables("QUERY_STRING")   
id=Int(replace(replace(server_v40,"/",""),".html",""))   
End If    
Call ReadNews()   
%>   
<div>   


标题: <b><%= News_title%></b><br />   
内容: <%=News_content%>   
</div>   

作者:不详 来源:网络
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 0759生活杂侃(www.0759gj.com) © 2024 版权所有 All Rights Reserved.
  • 公安备案:网监备4408013010516号 粤ICP备06030107号
  • Powered by laoy! V4.0.2

  • 部分文章来源于网络,若侵犯了您的权益请跟我们联系!