关键字:
WebServices实现 / Forms 认证 / 单点登录
使用webServices 登录(Forms认证)
背景:
>两个应用系统A,B
>A调用B.Login() webService --->返回Form验证传票(Cookies) ???
>等于是已经验证了,可以访问B系统了
这个方法是否可行?如果可行,调用WebService 之后,Cookies是否会自动返回到客户端,还是要自己写?
解决方法:
>调用端代码
System.Net.CookieContainer cookies
=
new
System.Net.CookieContainer() ;
WebRef.TextCoreAPI login = new Test.WebRef.TextCoreAPI() ; // webservices
login.CookieContainer = cookies ;
int result = login.Login( " kendo " , " kendo " ) ; // webservices 方法
// 注意以下语句
System.Net.CookieCollection cookCll = login.CookieContainer.GetCookies( new Uri(login.Url)) ;
foreach (Cookie cook in cookCll)
... {
HttpCookie cookie = new HttpCookie(cook.Name) ;
cookie.Name = cook.Name ;
cookie.Value = cook.Value ;
HttpContext.Current.Response.AppendCookie(cookie) ;
}
WebRef.TextCoreAPI login = new Test.WebRef.TextCoreAPI() ; // webservices
login.CookieContainer = cookies ;
int result = login.Login( " kendo " , " kendo " ) ; // webservices 方法
// 注意以下语句
System.Net.CookieCollection cookCll = login.CookieContainer.GetCookies( new Uri(login.Url)) ;
foreach (Cookie cook in cookCll)
... {
HttpCookie cookie = new HttpCookie(cook.Name) ;
cookie.Name = cook.Name ;
cookie.Value = cook.Value ;
HttpContext.Current.Response.AppendCookie(cookie) ;
}
>webservices:
关键是加上:
FormsAuthentication.SetAuthCookie(username,persist);