寻找 Response.Cookies(Forum_sn).path=cookiepath
应该共有1个
替换为:
Response.Cookies(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="/"
寻找 Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath 第26行
应该只有一个
替换为:
Response.Cookies(Dvbbs.Forum_sn).path="/"
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
Const.asp的完整代码为
<!--#Include File="Dv_ClsMain.asp"-->
<!--#include file="../WriteCookies.asp"-->
<%
Set MyBoardOnline=new Cls_UserOnlne
Dvbbs.GetForum_Setting
Dvbbs.CheckUserLogin
%>
基本思路 :单点登录
即在登录某一系统后 通过传值 跳转到另一系统登录 然后再返回初始页
一、Asp->asp.net
1、修改 bbs/inc/dv_clsmain.asp
38行 Forum_sn = "DvForum"
注释掉 Forum_sn=Forum_sn & "_" & Request.servervariables("SERVER_NAME")
这样 在asp.net中就可以 调用Request.Cookies["DvForum"]["userid"].value这样的由动网生成的Cookies。
2、修改 bbs/login.asp
将源代码 199行处 Response.Write TempStr
改为:
if Request("fromnet")<>"" then '来自asp.net的登录页
TempStr = "<script>location.href='"&comeurl&"';</script>"
Response.Write TempStr
else
comeurl = Replace(comeurl,"&","|")
Response.Redirect "userlogin.aspx?frombbs="&comeurl '
end if
其中:comeurl为动网变量,表示上一个url。
Request("fromnet")表示 现在asp.net站点登录 跳转到了login.asp页
userlogin.aspx 表示asp.net的登录页
3、在userlogin.aspx 中
用动网中的Request["DvForum"]["userid"]来获取 userid执行asp.net中的登录方法
然后 按Request["frombbs"]的值 跳转回去 (记得要Replace掉"|")
二、asp.net ->asp
在userlogin.aspx中用url传值 to login.asp
因为在动网中index.asp有个表单 用来传值到login.asp页,而在login.asp页中 是用Request("xx")取的值
所以url 和form传值通用
1、userlogin.aspx中的关键代码:
执行asp.net的登录操作后
if(Request["frombbs"]==null)
{
string ctype=Login.GetUserGroupType(sUserID);
string urlvalues="username="+HttpUtility.UrlEncode(sUserName,Encoding.GetEncoding("gb2312"))+"&codestr="+code+"&password="+inputpassword+"&action=chk&CookieDate=1&fromnet=1&comeurl="+sRequestUrl;
Response.Write("<script>alert('"+sUserName+"登录!');location.href='../bbs/login.asp?"+urlvalues+"';</script>");
}
else)//来自动网论坛
{
Response.Redirect("../bbs/login.aspx?frombbs="+Request["frombbs"]);//bbs/login.aspx是一个模拟动网的登录成功的效果页
}
注:我的asp.net的站点编码是utf-8的 如果你的是gb2312的
HttpUtility.UrlEncode(sUserName,Encoding.GetEncoding("gb2312"))换成用户名就行了
2、bbs/login.aspx
代码 code:
protected string Path="";
private void Page_Load(object sender, System.EventArgs e)
{
if(Request["frombbs"]!=null)
{
Path=Request["frombbs"];
Path=Path.Replace("|","&");
if(Path=="index.asp")
{
this.li_Control.Style.Add("display","none");
}
}
else
{
Path="index.asp";
}
}
HTML:
<meta http-equiv="refresh" c>
<table class="tableborder1" cellSpacing="1" cellPadding="3" align="center" width="100%">
<tr>
<th height="25">
登录成功:aspx主站论坛欢迎您的到来</th></tr>
<tr>
<td class="tablebody1"><br>
<ol>
<li id="li_Control" runat="server">
<A href="<%=Path%>">
<%=Path%>
</A>
</li>
<li>
<A href="index.asp">返回首页</A>
</li>
</ol>
</td>
</tr>
</table>
3、login.asp
15行 下
Dvbbs.Nav()
Dvbbs.Head_var 0,0,template.Strings(0),"login.asp"
改为:
if Request("fromnet")="" or isNUll (Request("fromnet")) then '来自于.net主站
Dvbbs.Nav()
Dvbbs.Head_var 0,0,template.Strings(0),"login.asp"
else
Response.Write "系统登录中..."
end if