asp.net与动网论坛的整合
思路:
在网站登陆的时候,写Cookies,访问论坛的时候读这个Cookies,如果存在的话,就查询动网的用户表,然后写动网自己的Cookies和Session
具体方法:
1.是要同步用户表,这个就不多说了.
2.在asp.net做的网站中登录成功后写一个cookie.
Response.Cookies["bhj"].Path = "/";
//实现全站共享cookie,如果不在同一个域中就设成同一个域
Response.Cookies["bhj"]["dUserName"] = "你的用户名";
Response.Cookies["bhj"]["dPassword"] = "你的密码";//要加密哦.
............................等等信息,在这里不多写了.
3.实现cookie的全站通用
必须修改三个文件:
①打开inc/Dv_ClsMain.asp
寻找 Response.Cookies(Forum_sn).path=cookiepath
应该共有1个
替换为:
Response.Cookies(Forum_sn).path="/"
寻找 Response.Cookies(Forum_sn).path=cookiepath
应该共有1个
替换为:
Response.Cookies(Forum_sn).path="/"
② 打开login.asp
寻找 Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
应该共有3个,其中一个是:Response.Cookies(Dvbbs.Forum_sn).path = Dvbbs.cookiepath(等号两旁有空格)
替换为:
Response.Cookies(Dvbbs.Forum_sn).path="/"
寻找 Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
应该共有3个,其中一个是:Response.Cookies(Dvbbs.Forum_sn).path = Dvbbs.cookiepath(等号两旁有空格)
替换为:
Response.Cookies(Dvbbs.Forum_sn).path="/"
③ 打开logout.asp
寻找 Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath 第26行
应该只有一个
替换为:
Response.Cookies(Dvbbs.Forum_sn).path="/"
寻找 Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath 第26行
应该只有一个
替换为:
Response.Cookies(Dvbbs.Forum_sn).path="/"
4.新建一个WriteCookies.asp的文件放在动网根目录。将下面这段代码复制进去
<%
session("flag")=empty
Response.Cookies("StatUserID")=Request.Cookies("StatUserID")
Dim ChinaUserName,ChinaPassword,TruePassWordChina
ChinaUserName = Trim(Request.Cookies("bhj")("dUserName"))
ChinaPassword = Trim(Request.Cookies("bhj")("dPassword"))
If ChinaUserName<> "" and ChinaPassword <> "" then
If ChkChina228Login(ChinaUserName,ChinaPassword,1,ChinaCreatepass(),1) then
End If
End if
Function ChkChina228Login(ChinaUserName,ChinaPassword,usercookies,TruePassWordChina,userhidden)
Dim rsUser,article,userclass,titlepic
Dim lastip,UserLastLogin
Dim GroupID,ClassSql,FoundGrade
Dim regname,iMyUserInfo
Dim sql,sqlstr,OLDuserhidden
Sql="Select UserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,lastlogin as cometime , LastLogin as activetime,UserLogins,Lockuser,Userclass,UserGroupID,UserGroup,userWealth,userEP,userCP,UserPower,UserBirthday,UserLastIP,UserDel,UserIsBest,UserHidden,UserMsg,IsChallenge,UserMobile,TitlePic,UserTitle,TruePassWord,UserToday,UserMoney,UserTicket,FollowMsgID,Vip_StarTime,Vip_EndTime,userid as boardid"
Sql=Sql & " From [Dv_User] Where UserName='"&ChinaUserName&"'"
set rsUser=Dvbbs.Execute(sql)
If rsUser.eof and rsUser.bof Then
ChkChina228Login=False
Exit Function
Else
If rsUser("Lockuser") =1 or rsUser("UserGroupID") =5 Then
ChkChina228Login=False
Exit Function
Else
If Trim(ChinaPassword)=Trim(rsUser("UserPassword")) Then
ChkChina228Login=True
Dvbbs.UserID=RsUser("UserID")
RegName = RsUser("UserName")
Article= RsUser("UserPost")
UserLastLogin = RsUser("cometime")
UserClass = RsUser("Userclass")
GroupID = RsUser("userGroupID")
OLDuserhidden=RsUser("UserHidden")
TitlePic = RsUser("UserTitle")
If Article < 0 Then Article=0
Set Dvbbs.UserSession=Dvbbs.RecordsetToxml(rsUser,"userinfo","xml")
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@cometime").text=Now()
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@activetime").text=DateAdd("s",-3600,Now())
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@boardid").text=0
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo").attributes.setNamedItem(Dvbbs.UserSession.createNode(2,"isuserpermissionall","")).text=Dvbbs.FoundUserPermission_All()
If OLDuserhidden <> CLng(userhidden) Then
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userhidden").text=userhidden
Dvbbs.Execute("update Dv_user set userhidden="&userhidden&" where UserId=" & Dvbbs.UserID)
End If
Dim BS
Set Bs=Dvbbs.GetBrowser()
Dvbbs.UserSession.documentElement.appendChild(Bs.documentElement)
If EnabledSession Then Session(Dvbbs.CacheName & "UserID")=Dvbbs.UserSession.xml
Else
ChkChina228Login=False
Exit Function
End If
End If
End If
If ChkChina228Login Then
Set rsUser=Dvbbs.Execute("Select MinArticle,IsSetting,ParentGID,UserTitle,GroupPic From Dv_UserGroups Where UserGroupID="&GroupID)
If Not (rsUser.Eof And rsUser.Bof) Then
If rsUser(2)=1 or rsUser(2)=2 or rsUser(2)=4 or rsUser(2)=5 Then
'用户等级不按照文章升级,用户为系统或特殊或多属性组
UserClass=rsUser(3)
TitlePic=rsUser(4)
FoundGrade=True
End If
End If
If Not FoundGrade Then
'如果不属于系统或特殊或多属性组,则将该用户属于注册用户组且按照其文章数自动更新其用户组(等级)
Set rsUser=Dvbbs.Execute("Select Top 1 usertitle,GroupPic,UserGroupID From Dv_UserGroups Where ParentGID=3 And Minarticle<="&Article&" order By MinArticle Desc,UserGroupID")
If Not (rsUser.Eof And rsUser.Bof) Then
UserClass=rsUser(0)
TitlePic=rsUser(1)
GroupID=rsUser(2)
FoundGrade=True
End If
End If
Set rsUser=nothing
If Not FoundGrade Then
ChkChina228Login=False
Exit Function
end if
sql="update [Dv_User] set LastLogin="&SqlNowString&",UserLogins=UserLogins+1,UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWordChina&"' where userid="&dvbbs.UserID
Dvbbs.Execute(sql)
Dim StatUserID,UserSessionID
StatUserID = Dvbbs.checkStr(Trim(Request.Cookies(Dvbbs.Forum_sn)("StatUserID")))
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then
StatUserID = Replace(Dvbbs.UserTrueIP,".","")
UserSessionID = Replace(Startime,".","")
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then StatUserID = 0
StatUserID = Ccur(StatUserID) + Ccur(UserSessionID)
End If
StatUserID = Ccur(StatUserID)
Dvbbs.Execute("delete from dv_online where id="&StatUserID&"")
If trim(ChinaUserName)<>trim(Dvbbs.membername) Then
Response.Cookies(Dvbbs.Forum_sn)("username")=""
Response.Cookies(Dvbbs.Forum_sn)("password")=""
Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
Response.Cookies(Dvbbs.Forum_sn)("userid")=""
Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
Dvbbs.Execute("delete from dv_online where username='"&Dvbbs.membername&"'")
End If
If isnull(usercookies) or usercookies="" Then usercookies="0"
select case usercookies
case "0"
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 1
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+1
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 2
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+31
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 3
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+365
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
end select
Response.Cookies(Dvbbs.Forum_sn).Domain = "china228.com"
Response.Cookies(Dvbbs.Forum_sn)("StatUserID") = StatUserID
Response.Cookies(Dvbbs.Forum_sn)("username") = Regname
Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWordChina
Response.Cookies(Dvbbs.Forum_sn)("userclass") = userclass
Response.Cookies(Dvbbs.Forum_sn)("userid") = Dvbbs.UserID
Response.Cookies(Dvbbs.Forum_sn)("userhidden") = 2
rem 清除图片上传数的限制
Response.Cookies("upNum")=0
Dvbbs.Membername=Dvbbs.Checkstr(regname)
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@truepassword").text= TruePassWordChina
Dvbbs.Memberclass=Dvbbs.Checkstr(userclass)
Dvbbs.UserGroupID=GroupID
End If
End Function
Function ChinaCreatepass()'系统分配随机密码
Dim Ran,i,LengthNum
LengthNum=16
ChinaCreatepass=""
For i=1 To LengthNum
Randomize
Ran = CInt(Rnd * 2)
Randomize
If Ran = 0 Then
Ran = CInt(Rnd * 25) + 97
ChinaCreatepass = ChinaCreatepass& UCase(Chr(Ran))
ElseIf Ran = 1 Then
Ran = CInt(Rnd * 9)
ChinaCreatepass = ChinaCreatepass & Ran
ElseIf Ran = 2 Then
Ran = CInt(Rnd * 25) + 97
ChinaCreatepass =ChinaCreatepass& Chr(Ran)
End If
Next
End Function
Response.Cookies("StatUserID")=Request.Cookies("StatUserID")
Dim ChinaUserName,ChinaPassword,TruePassWordChina
ChinaUserName = Trim(Request.Cookies("bhj")("dUserName"))
ChinaPassword = Trim(Request.Cookies("bhj")("dPassword"))
If ChinaUserName<> "" and ChinaPassword <> "" then
If ChkChina228Login(ChinaUserName,ChinaPassword,1,ChinaCreatepass(),1) then
End If
End if
Function ChkChina228Login(ChinaUserName,ChinaPassword,usercookies,TruePassWordChina,userhidden)
Dim rsUser,article,userclass,titlepic
Dim lastip,UserLastLogin
Dim GroupID,ClassSql,FoundGrade
Dim regname,iMyUserInfo
Dim sql,sqlstr,OLDuserhidden
Sql="Select UserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,lastlogin as cometime , LastLogin as activetime,UserLogins,Lockuser,Userclass,UserGroupID,UserGroup,userWealth,userEP,userCP,UserPower,UserBirthday,UserLastIP,UserDel,UserIsBest,UserHidden,UserMsg,IsChallenge,UserMobile,TitlePic,UserTitle,TruePassWord,UserToday,UserMoney,UserTicket,FollowMsgID,Vip_StarTime,Vip_EndTime,userid as boardid"
Sql=Sql & " From [Dv_User] Where UserName='"&ChinaUserName&"'"
set rsUser=Dvbbs.Execute(sql)
If rsUser.eof and rsUser.bof Then
ChkChina228Login=False
Exit Function
Else
If rsUser("Lockuser") =1 or rsUser("UserGroupID") =5 Then
ChkChina228Login=False
Exit Function
Else
If Trim(ChinaPassword)=Trim(rsUser("UserPassword")) Then
ChkChina228Login=True
Dvbbs.UserID=RsUser("UserID")
RegName = RsUser("UserName")
Article= RsUser("UserPost")
UserLastLogin = RsUser("cometime")
UserClass = RsUser("Userclass")
GroupID = RsUser("userGroupID")
OLDuserhidden=RsUser("UserHidden")
TitlePic = RsUser("UserTitle")
If Article < 0 Then Article=0
Set Dvbbs.UserSession=Dvbbs.RecordsetToxml(rsUser,"userinfo","xml")
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@cometime").text=Now()
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@activetime").text=DateAdd("s",-3600,Now())
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@boardid").text=0
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo").attributes.setNamedItem(Dvbbs.UserSession.createNode(2,"isuserpermissionall","")).text=Dvbbs.FoundUserPermission_All()
If OLDuserhidden <> CLng(userhidden) Then
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userhidden").text=userhidden
Dvbbs.Execute("update Dv_user set userhidden="&userhidden&" where UserId=" & Dvbbs.UserID)
End If
Dim BS
Set Bs=Dvbbs.GetBrowser()
Dvbbs.UserSession.documentElement.appendChild(Bs.documentElement)
If EnabledSession Then Session(Dvbbs.CacheName & "UserID")=Dvbbs.UserSession.xml
Else
ChkChina228Login=False
Exit Function
End If
End If
End If
If ChkChina228Login Then
Set rsUser=Dvbbs.Execute("Select MinArticle,IsSetting,ParentGID,UserTitle,GroupPic From Dv_UserGroups Where UserGroupID="&GroupID)
If Not (rsUser.Eof And rsUser.Bof) Then
If rsUser(2)=1 or rsUser(2)=2 or rsUser(2)=4 or rsUser(2)=5 Then
'用户等级不按照文章升级,用户为系统或特殊或多属性组
UserClass=rsUser(3)
TitlePic=rsUser(4)
FoundGrade=True
End If
End If
If Not FoundGrade Then
'如果不属于系统或特殊或多属性组,则将该用户属于注册用户组且按照其文章数自动更新其用户组(等级)
Set rsUser=Dvbbs.Execute("Select Top 1 usertitle,GroupPic,UserGroupID From Dv_UserGroups Where ParentGID=3 And Minarticle<="&Article&" order By MinArticle Desc,UserGroupID")
If Not (rsUser.Eof And rsUser.Bof) Then
UserClass=rsUser(0)
TitlePic=rsUser(1)
GroupID=rsUser(2)
FoundGrade=True
End If
End If
Set rsUser=nothing
If Not FoundGrade Then
ChkChina228Login=False
Exit Function
end if
sql="update [Dv_User] set LastLogin="&SqlNowString&",UserLogins=UserLogins+1,UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWordChina&"' where userid="&dvbbs.UserID
Dvbbs.Execute(sql)
Dim StatUserID,UserSessionID
StatUserID = Dvbbs.checkStr(Trim(Request.Cookies(Dvbbs.Forum_sn)("StatUserID")))
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then
StatUserID = Replace(Dvbbs.UserTrueIP,".","")
UserSessionID = Replace(Startime,".","")
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then StatUserID = 0
StatUserID = Ccur(StatUserID) + Ccur(UserSessionID)
End If
StatUserID = Ccur(StatUserID)
Dvbbs.Execute("delete from dv_online where id="&StatUserID&"")
If trim(ChinaUserName)<>trim(Dvbbs.membername) Then
Response.Cookies(Dvbbs.Forum_sn)("username")=""
Response.Cookies(Dvbbs.Forum_sn)("password")=""
Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
Response.Cookies(Dvbbs.Forum_sn)("userid")=""
Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
Dvbbs.Execute("delete from dv_online where username='"&Dvbbs.membername&"'")
End If
If isnull(usercookies) or usercookies="" Then usercookies="0"
select case usercookies
case "0"
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 1
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+1
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 2
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+31
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
case 3
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+365
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
end select
Response.Cookies(Dvbbs.Forum_sn).Domain = "china228.com"
Response.Cookies(Dvbbs.Forum_sn)("StatUserID") = StatUserID
Response.Cookies(Dvbbs.Forum_sn)("username") = Regname
Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWordChina
Response.Cookies(Dvbbs.Forum_sn)("userclass") = userclass
Response.Cookies(Dvbbs.Forum_sn)("userid") = Dvbbs.UserID
Response.Cookies(Dvbbs.Forum_sn)("userhidden") = 2
rem 清除图片上传数的限制
Response.Cookies("upNum")=0
Dvbbs.Membername=Dvbbs.Checkstr(regname)
Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@truepassword").text= TruePassWordChina
Dvbbs.Memberclass=Dvbbs.Checkstr(userclass)
Dvbbs.UserGroupID=GroupID
End If
End Function
Function ChinaCreatepass()'系统分配随机密码
Dim Ran,i,LengthNum
LengthNum=16
ChinaCreatepass=""
For i=1 To LengthNum
Randomize
Ran = CInt(Rnd * 2)
Randomize
If Ran = 0 Then
Ran = CInt(Rnd * 25) + 97
ChinaCreatepass = ChinaCreatepass& UCase(Chr(Ran))
ElseIf Ran = 1 Then
Ran = CInt(Rnd * 9)
ChinaCreatepass = ChinaCreatepass & Ran
ElseIf Ran = 2 Then
Ran = CInt(Rnd * 25) + 97
ChinaCreatepass =ChinaCreatepass& Chr(Ran)
End If
Next
End Function
%>
5.打开inc/const.asp,在第二行加<!--#include file="../WriteCookies.asp"-->
Const.asp的完整代码为
<!--#Include File="Dv_ClsMain.asp"-->
<!--#include file="../WriteCookies.asp"-->
<%
Set MyBoardOnline=new Cls_UserOnlne
Dvbbs.GetForum_Setting
Dvbbs.CheckUserLogin
%>
Const.asp的完整代码为
<!--#Include File="Dv_ClsMain.asp"-->
<!--#include file="../WriteCookies.asp"-->
<%
Set MyBoardOnline=new Cls_UserOnlne
Dvbbs.GetForum_Setting
Dvbbs.CheckUserLogin
%>
6.把动网论坛的logout.asp(注销功能)文件打开打到如下内容
Response.Cookies(Dvbbs.Forum_sn).path="/"
Response.Cookies(Dvbbs.Forum_sn)("username")=""
Response.Cookies(Dvbbs.Forum_sn)("password")=""
Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
Response.Cookies(Dvbbs.Forum_sn)("userid")=""
Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
很明显上面的代码是用来置空cookie的,在下面添上几行,
Response.Cookies("bhj")("dUserName")=""
Response.Cookies("bhj")("dPassword")=""
......................................
这几行的意思是清调你写入的cookie信息.