碰到问题了.高手们来帮帮我吧..

山里老妖怪 2006-05-29 12:44:48
asp.net做的会员系统已经制作完毕.
近日买了一套OBLOG系统.欲与之进行会员整合
根据官方提提供的整合方法做了一个API.实现了注册同步.但是在做登陆同步的时候碰到了问题
在ASP里面能过SXML2.ServerXMLHTTP.3.0对象提交数据到asp.net会员系统的时候,通过调试证明Cookie和Session已生成,但是我通过刷新asp.net页面试图来取Session和Cookies的时候,却取不到值:

以下是API的代码:

public class UserAPI:IHttpHandler,IRequiresSessionState
{


public void ProcessRequest(HttpContext context)
{
APIConfig config=new APIConfig();
if(!config.Enable)
{
ApiClass.SendResult(config.AppID,1,"系统并未开启整合接口!");
return;
}
if(context.Request.InputStream.Length>0)
{
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(context.Request.InputStream);
string appid=xmlDoc.SelectSingleNode("//appid").InnerText;
string syskey=xmlDoc.SelectSingleNode("//syskey").InnerText;
string action=xmlDoc.SelectSingleNode("//action").InnerText;
string UserName=xmlDoc.SelectSingleNode("//username").InnerText;
if(ApiClass.ChkSysKey(syskey,UserName))
{
Model.MemberUser mu;
string Message="";
switch(action.ToLower())
{
case "reguser":
mu=GetRequestUser(xmlDoc);
if(BLL.MemberUser.add(mu,out Message))
{
ApiClass.SendResult(config.AppID,0,"");
}
else
{
ApiClass.SendResult(config.AppID,1,Message);

}
break;
case "login":
string password=xmlDoc.SelectSingleNode("//password").InnerText;
string userIp=xmlDoc.SelectSingleNode("//userip").InnerText;
string Cookie=xmlDoc.SelectSingleNode("//savecookie").InnerText;
string UID="";
ArrayList al=new ArrayList();
bool islogin=BLL.MemberUser.Login(UserName,password,out UID,1,out al);
doLogin(islogin,al,CookieDays(Cookie),UID);
break;
case "logout":
break;
case "update":
break;
case "delete":
break;
case "getinfo":
break;
case "checkname":
if(BLL.user.exists(UserName.Trim()))
{
ApiClass.SendResult(config.AppID,1,"该用户已经存在!");
}
else
{
ApiClass.SendResult(config.AppID,0,"");
}
break;
}
}
else
{
ApiClass.SendResult(config.AppID,1,"安全码验证未通过!");
return;
}

}
else
{
ApiClass.SendResult(config.AppID,1,"接收数据出错,请重试!");
return;
}
}
void doLogin(bool islogin,ArrayList al,int Cookie,string UserID)
{
APIConfig config=new APIConfig();
if(islogin==false)
{
string Message="";
for(int i=0;i<al.Count;i++)
{
Message+="<li>"+((Exception)al[i]).Message+"</li>";
}
ApiClass.SendResult(config.AppID,1,Message);
}
else
{
user.UserLogin(UserID,Cookie);
ApiClass.WriteLog("登陆了");
ApiClass.SendResult(config.AppID,0,"");

}
}
int CookieDays(string CaseValue)
{
switch(CaseValue)
{
case "0":
return 0;
case "1":
return 1;
case "2":
return 30;
case "3":
return 365;
default:
return 0;

}
}
Model.MemberUser GetRequestUser(XmlDocument xmlDoc)
{
Model.MemberUser mu=new Model.MemberUser();
mu.PASSWORDFORMAT=4;
mu.USERPASSWORD=Common.DEC.Encrypt(mu.PASSWORDFORMAT,xmlDoc.SelectSingleNode("//password").InnerText);
mu.USERNAME=xmlDoc.SelectSingleNode("//username").InnerText;
mu.LASTLOGINIP=xmlDoc.SelectSingleNode("//userip").InnerText;
mu.MEMBEREMAIL=xmlDoc.SelectSingleNode("//email").InnerText;
mu.QUESTION=xmlDoc.SelectSingleNode("//question").InnerText;
mu.ANSWER=xmlDoc.SelectSingleNode("//answer").InnerText;
string sex=xmlDoc.SelectSingleNode("//gender").InnerText;
ApiClass.WriteLog("性别是|"+sex+"|");
if((!Common.ValidateUtil.isNumeric(sex))||sex==String.Empty)
{
mu.MEMBERSEX=0;
}
else
{
mu.MEMBERSEX=Convert.ToInt32(sex);
}
mu.ISDELETED=false;
mu.ISACTIVE=true;
mu.ISLOCK=false;
mu.JOINDATE=DateTime.Now;
mu.MEMBERNAME=xmlDoc.SelectSingleNode("//truename").InnerText;
mu.MEMBERBIRTHDAY=xmlDoc.SelectSingleNode("//birthday").InnerText;
mu.MEMBERBP=xmlDoc.SelectSingleNode("//telephone").InnerText;
mu.MEMBERADDR=xmlDoc.SelectSingleNode("//address").InnerText;
return mu;
}

public bool IsReusable
{
get
{
return true;
}
}

#endregion
}
}

...全文
150 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dafeifei 2006-05-29
  • 打赏
  • 举报
回复
看死人了,能不能简短一点,跟踪一下,找到问题点再发问,呵呵
山里老妖怪 2006-05-29
  • 打赏
  • 举报
回复
没有跨域的情况
iwebsms 2006-05-29
  • 打赏
  • 举报
回复
一般你会采用2个域来操作,例如bbs.***.com和blog.***.com
这样的话就会存在跨域问题,通常跨域是无法共享数据的




=====================================================
插播广告
=====================================================

大海网络(www.dahai.net)最新虚拟主机产品价格表

HTML-A 100M HTML 空间;赠送25M电子邮件; 价格:72元
HTML-B 200M HTML 空间;赠送50M电子邮件; 价格:112元
HTML-C 400M HTML 空间;赠送100M电子邮件; 价格:192元
HTML-D 800M HTML 空间;赠送200M电子邮件; 价格:272元
HTML-E 50M HTML 空间;赠送5M电子邮件; 价格:65元

ASP-A 100M ASP 空间;赠送25M电子邮件; 价格:96元
ASP-B 200M ASP 空间;赠送50M电子邮件; 价格:136元
ASP-C 400M ASP 空间;赠送100M电子邮件; 价格:216元
ASP-D 800M ASP 空间;赠送200M电子邮件; 价格:376元
ASP-E 50M ASP 空间;赠送5M电子邮件; 价格:86元

ASP.NET-A 100M ASP.NET 空间;赠送25M电子邮件; 价格:112元
ASP.NET-B 200M ASP.NET 空间;赠送50M电子邮件; 价格:192元
ASP.NET-C 400M ASP.NET 空间;赠送100M电子邮件; 价格:328元
ASP.NET-D 800M ASP.NET 空间;赠送200M电子邮件; 价格:432元

SQL-A 50M SQL Server 数据库空间; 价格:112元
SQL-B 100M SQL Server 数据库空间; 价格:192元
SQL-C 200M SQL Server 数据库空间; 价格:328元
SQL-D 400M SQL Server 数据库空间; 价格:432元


英文国际顶级域名(.com/.net/.org) 价格:50元
英文国内域名(.cn/.com.cn/.net.cn/.org.cn) 价格:45元
山里老妖怪 2006-05-29
  • 打赏
  • 举报
回复
-------------------------------------------------------------------
以下是APIClass的代码:

using System;
using System.Xml;
using System.Web;
using System.Net;
using System.IO;
using System.Collections.Specialized;

namespace MemberSystem.API
{
/// <summary>
/// API_Class 的摘要说明。
/// </summary>
public class ApiClass
{
public ApiClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void SendResult(string appid,int status,string msg)
{
XmlDocument xmlDoc=LoadXML(false);
xmlDoc=SetNodeValue(xmlDoc,"//appid",appid);
xmlDoc=SetNodeValue(xmlDoc,"//status",status.ToString());
xmlDoc=SetNodeValue(xmlDoc,"//message",msg);
ResponseXML(xmlDoc);
}
public static bool ProcessPost(Model.MemberUser mu,string action,out string Message)
{
XmlDocument xmlDoc=IniPost(mu.USERNAME,action);
switch(action.Trim().ToLower())
{
case "reguser":
case "update":
xmlDoc=SetNodeValue(xmlDoc,"//password",mu.USERPASSWORD);
xmlDoc=SetNodeValue(xmlDoc,"//email",mu.MEMBEREMAIL);
xmlDoc=SetNodeValue(xmlDoc,"//question",mu.QUESTION);
xmlDoc=SetNodeValue(xmlDoc,"//answer",mu.ANSWER);
xmlDoc=SetNodeValue(xmlDoc,"//gender",mu.MEMBERSEX.ToString());
xmlDoc=SetNodeValue(xmlDoc,"//birthday",mu.MEMBERBIRTHDAY);
xmlDoc=SetNodeValue(xmlDoc,"//telephone",mu.MEMBERHP);
xmlDoc=SetNodeValue(xmlDoc,"//userip",Common.function.getIp());
xmlDoc=SetNodeValue(xmlDoc,"//userstatus",Convert.ToInt32(mu.ISACTIVE).ToString());
xmlDoc=SetNodeValue(xmlDoc,"//address",mu.MEMBERADDR);
break;
case "login":
xmlDoc=SetNodeValue(xmlDoc,"//password",mu.USERPASSWORD);
xmlDoc=SetNodeValue(xmlDoc,"//savecookie","1");
xmlDoc=SetNodeValue(xmlDoc,"//userip",Common.function.getIp());
break;
default:
break;
}
APIConfig config=new APIConfig();
NameValueCollection al=config.Urls;
bool IsOk=true;
string message="";
for(int i=0;i<al.Count;i++)
{
XmlDocument XmlResult=SendPost(al[i].ToString(),xmlDoc);
string status=XmlResult.SelectSingleNode("//status").InnerText;
if(status.Trim()!="0")
{
IsOk=false;
message+=XmlResult.SelectSingleNode("//appid").InnerText+"提示:"+XmlResult.SelectSingleNode("//message").InnerText;
}
}
Message=message;
return IsOk;

}
public static XmlDocument IniPost(string UserName,string Action)
{
APIConfig config=new APIConfig();
XmlDocument xmlDoc=LoadXML(true);
xmlDoc=SetNodeValue(xmlDoc,"//appid",config.AppID);
xmlDoc=SetNodeValue(xmlDoc,"//syskey",Common.DEC.Encrypt(4,UserName+config.Key).ToLower());
xmlDoc=SetNodeValue(xmlDoc,"//action",Action);
xmlDoc=SetNodeValue(xmlDoc,"//username",UserName);
return xmlDoc;
}
public static XmlDocument SendPost(string url,XmlDocument xmlDoc)
{
HttpWebRequest xmlHttp=(HttpWebRequest)WebRequest.Create(url);
byte[] PostData=System.Text.Encoding.ASCII.GetBytes(xmlDoc.InnerXml);
xmlHttp.ContentType="application/x-www-form-urlencoded";
xmlHttp.ContentLength=PostData.Length;
xmlHttp.Method="Post";
xmlHttp.Timeout=10000;
Stream ms=xmlHttp.GetRequestStream();
ms.Write(PostData,0,PostData.Length);
XmlDocument xmlReturn=new XmlDocument();
HttpWebResponse ReturnData=(HttpWebResponse)xmlHttp.GetResponse();
xmlReturn.Load(ReturnData.GetResponseStream());
xmlHttp.Abort();
return xmlReturn;

}
public static void WriteLog(string Message)
{
System.IO.StreamReader sr=new System.IO.StreamReader("c:\\MemberSystemLog.txt");
Message=sr.ReadToEnd()+Message;
sr.Close();
System.IO.StreamWriter sm=new System.IO.StreamWriter("c:\\MemberSystemLog.txt");
sm.WriteLine(Message);
sm.Close();
}
public static bool ChkSysKey(string sysKey,string userName)
{
APIConfig config=new APIConfig();
if(sysKey.Length==16)
{
if(sysKey.ToLower().Equals(Common.DEC.Encrypt(4,userName+config.Key).ToLower()))
return true;
else
return false;
}
else if(sysKey.Length==32)
{
if(sysKey.ToLower().Equals(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userName+config.Key,"md5").ToLower()))
return true;
else
return false;
}
else
return false;
}
public static void ResponseXML(XmlDocument xmlDoc)
{
HttpContext.Current.Response.ContentType="text/xml";
HttpContext.Current.Response.Charset="gb2312";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Output.Write(xmlDoc.InnerXml);
}
public static XmlDocument SetNodeValue(XmlDocument xmlDoc,string NodeName,string NodeValue)
{
XmlNode xn=xmlDoc.SelectSingleNode(NodeName);
xn.InnerText=NodeValue;
return xmlDoc;
}
public static XmlDocument LoadXML(bool IsRequest)
{
string xmlPath;
if(IsRequest)
xmlPath=System.Web.HttpContext.Current.Server.MapPath("~")+"\\API\\Request.xml";
else
xmlPath=System.Web.HttpContext.Current.Server.MapPath("~")+"\\API\\Response.xml";
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(xmlPath);
return xmlDoc;

}
}
}

-----------------------------------------------------------------------------------
以下是登陆的代码:
public static void UserLogin(string UserId,int CookiesDays)
{
string UserName;
UserName=BLL.user.UserName(UserId);

if(CookiesDays!=0)
{
System.Web.Security.FormsAuthentication.SetAuthCookie(UserName, false);
System.Web.HttpContext.Current.Response.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddDays(Convert.ToInt32(CookiesDays));
API.ApiClass.WriteLog("保存了Cookie");
}
else
{
System.Web.Security.FormsAuthentication.SetAuthCookie(UserName, true);

API.ApiClass.WriteLog("没有保存Cookie");
}
Session_User(UserId);
API.ApiClass.WriteLog("保存了Session");
API.ApiClass.WriteLog(System.Web.HttpContext.Current.User.Identity.IsAuthenticated.ToString());
//Cache_User(UserId,new TimeSpan(CookiesDays+10,0,0,0,0));

}
public static void UserLogout()
{
System.Web.Security.FormsAuthentication.SignOut();
}
请高手帮帮我
我的QQ:34632092,msn:free1z@hotmail.com欢迎高手帮我指点..谢谢
ilovejolly 2006-05-29
  • 打赏
  • 举报
回复
mark
sbsrg3000 2006-05-29
  • 打赏
  • 举报
回复
MARK 是呼,不看广告看疗效
自然框架 2006-05-29
  • 打赏
  • 举报
回复
帮你顶
dgrwang 2006-05-29
  • 打赏
  • 举报
回复
太长,怎么广告都用

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧