All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
如何测试,Macintosh,Web,服务器_php资料_编程技术
ASP.NET2.0数据操作之创建业务逻辑层_[Asp.Net教程]
Visual,Studio.NET,安装错误_.net资料_编程技术
C#程序的访问修饰符介绍_[Asp.Net教程]
几种asp.net操作数据库的基础代码_[Asp.Net教程]
Delphi以图形按钮显示的界面
ASP.NET实例:在GridView使用HyperLinkField,属性的链接_[Asp.Net教程]
通过查询分析器对比SQL语句的执行效率_[SQL,Server教程]
三个SQL视图查出所有SQL Server数据库字典_[SQL Server教程]
visual c++定制状态栏
Reading number is top 10 pictures
Small QiShu -- ShuangShuangPan1
Shandong jinan is about to dismantle a one hundred-year history of the building
住院一星期,检测费两万
中国的十元人民币的秘密
到南昌西站了3
鸡也看毛片
NeedWallpaper4
Rendez-vous Sleep with actress, three days to earn 600000
星星命名法则
[猫扑大杂烩]华东师范墙上看到的捐精告示 15毫升3600元
Download software ranking
电车之狼R
Tram sex maniac 2 (H) rar bag17
好色的外科大夫
Proficient in JavaScript
C#编程思想
Unix video tutorial11
1400篇各类破解文章
天龙八部十二宫服务端
尖东毒玫瑰A
SP4 for SQL2000
归海一刀 published in(发表于) 2014/1/30 1:10:46 Edit(编辑)
新瓶旧酒ASP.NET,AJAX(10),-,客户端脚本编程(Sys.Services命名空间下的)_[Asp.Net教程]

新瓶旧酒ASP.NET,AJAX(10),-,客户端脚本编程(Sys.Services命名空间下的)_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(10) - 客户端脚本编程(Sys.Services命名空间下的)_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(10) - 客户端脚本编程(Sys.Services命名空间下的类)



介绍
ASP.NET AJAX的Sys.Services.AuthenticationService类、Sys.Services.ProfileService类、Sys.Services.ProfileGroup类完美地和ASP.NET 2.0的Membership和Profile进行了集成



关键
1、Sys.Services.AuthenticationService类的login()方法
Sys.Services.AuthenticationService.login(userName, password, isPersistent, customInfo, redirectUrl, loginCompletedCallback, failedCallback, userContext);
·userName - 用户名
·password - 密码
·isPersistent - 是否跨浏览器保存认证信息(持久保留)
·customInfo - 保留字段,可能在将来使用
·redirectUrl - 登录成功后重定向到的URL
·loginCompletedCallback - 登录成功后的回调函数
·failedCallback - 登录失败后的回调函数
·userContext - 用户上下文
WebService中与其对应的方法 - public bool Login()


2、登录成功后的回调函数
function LoginComplete(bool validCredentials, userContext, methodName)
·validCredentials - 是否成功通过了验证
·userContext - 用户上下文
·methodName - 调用的方法名


3、Sys.Services.AuthenticationService类的logout()方法
Sys.Services.AuthenticationService.logout(redirectUrl, logoutCompletedCallback, failedCallback, userContext);
·redirectUrl - 注销成功后重定向到的URL
·logoutCompletedCallback - 注销成功后的回调函数
·failedCallback - 注销失败后的回调函数
·userContext - 用户上下文
WebService中与其对应的方法 - public void Logout()


4、注销成功后的回调函数
function LogoutComplete(result, userContext, methodName)
·result - 保留字段,可能在将来使用,始终为null
·userContext - 用户上下文
·methodName - 调用的方法名


5、Sys.Services.AuthenticationService类的属性
·defaultLoginCompletedCallback - 登录成功后的回调函数
·defaultLogoutCompletedCallback - 注销成功后的回调函数
·defaultFailedCallback - 登录或注销失败后的回调函数
·isLoggedIn - 当前用户是否已经登录
·path - authentication service路径
·timeout - 超时时间


6、Sys.Services.ProfileService类的load()方法
Sys.Services.ProfileService.load(propertyNames, loadCompletedCallback, failedCallback, userContext);
·propertyNames - Profile属性名称数组
·loadCompletedCallback - 成功后的回调函数
·failedCallback - 失败后的回调函数
·userContext - 用户上下文
WebService中与其对应的方法 - public IDictionary GetAllPropertiesForCurrentUser()和public IDictionary GetPropertiesForCurrentUser(string[] properties)


7、读取Profile成功后的回调函数
function onLoadCompleted(numProperties, userContext, methodName)
·numProperties - 返回的Profile属性个数
·userContext - 用户上下文
·methodName - 调用的方法名


8、Sys.Services.ProfileService类的save()方法
Sys.Services.ProfileService.load(propertyNames, saveCompletedCallback, failedCallback, userContext);
·propertyNames - Profile属性名称数组
·saveCompletedCallback - 成功后的回调函数
·failedCallback - 失败后的回调函数
·userContext - 用户上下文
·WebService中与其对应的方法 - public int SetPropertiesForCurrentUser(IDictionary values)


9、保存Profile成功后的回调函数
onSaveCompleted(numProperties, userContext, methodName)
·numProperties - 保存的Profile属性个数
·userContext - 用户上下文
·methodName - 调用的方法名


10、Sys.Services.ProfileService类的属性
·读取或设置某个Profile的属性要这么写 - Sys.Services.ProfileService.properties.FieldName;
·defaultLoadCompletedCallback - 读取Profile成功后的回调函数
·defaultSaveCompletedCallback - 保存Profile成功后的回调函数
·defaultFailedCallback - 读取或保存Profile失败后的回调函数
·path - profile service路径
·timeout - 超时时间


11、Sys.Services.ProfileGroup类
·定义一个Profile组(同时需要在Web.config中定义)


12、登录或注销失败、读取或保存Profile失败后的回调函数
function onFailed(error, userContext, methodName)
·error - Sys.Net.WebServiceError对象
·userContext - 用户上下文
·methodName - 调用的方法名


13、如果要自动调用相关服务的话,则需要在web.config中的节点下增加类似如下的配置


readAccessProperties="Age, Salary"
writeAccessProperties="Age, Salary"
/>


示例
AuthenticationService.asmx
<%@ WebService Language="C#" Class="AuthenticationService" %>


using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class AuthenticationService : System.Web.Services.WebService
{
/**////


/// 登录
///

/// 用户名
/// 密码
/// 是否跨浏览器保存认证信息(持久保留)
///
[WebMethod]
public bool Login(string userName, string password, bool createPersistentCookie)
{
//Place code here.


System.Web.Security.FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
return true;
}


/**////


/// 注销
///

[WebMethod]
public void Logout()
{
//Place code here.
}
}



ProfileService.asmx
<%@ WebService Language="C#" Class="ProfileService" %>


using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ProfileService : System.Web.Services.WebService
{
/**////


/// 获取用户的全部Profile
///

///
[WebMethod]
public IDictionary GetAllPropertiesForCurrentUser()
{
Dictionary dic = new Dictionary();


dic.Add("Age", 27);
dic.Add("Salary", 100);


Article article = new Article();
article.Title = "Article Title From Server";
article.PublishTime = DateTime.Now;


dic.Add("Article", article);


return dic;
}


/**////


/// 获取用户的指定的Profile
///

/// 属性名称数组
///
[WebMethod]
public IDictionary GetPropertiesForCurrentUser(string[] properties)
{
//Place code here.
return null;
}


/**////


/// 保存用户的Profile
///

/// 用户的Profile的字典数据
///
[WebMethod]
public int SetPropertiesForCurrentUser(IDictionary values)
{
//Place code here.
return values.Count;
}
}


/**////


/// Article实体类
///

///
/// 示例而已,实际项目中要继承自System.Web.Profile.ProfileBase
///

public class Article
{
private string _title;
/**////
/// 文章标题
///

public string Title
{
get { return _title; }
set { _title = value; }
}


private DateTime _publishTime;
/**////


/// 文章发布日期
///

public DateTime PublishTime
{
get { return _publishTime; }
set { _publishTime = value; }
}
}


Sample.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sample.aspx.cs"
Inherits="ClientScripting_SysServices_Sample" Title="Sys.Services命名空间下的类" %>





帐号:



密码:



&nbsp;



onclick="btnLogin_click()" />
onclick="btnLogout_click()" />



&nbsp;



年龄:



薪水:



onclick="btnSave_click()" />
onclick="btnLoad_click()" />




&nbsp;






ScriptManager的设置




Web.config中的相关设置(在节点下)








运行结果
1、页面加载后
AuthenticationService path:/Web/ClientScripting/SysServices/AuthenticationService.asmx
AuthenticationService timeout:0
ProfileService path:ProfileService.asmx
ProfileService timeout:0


2、单击“登录”按钮
登录成功
用户上下文:用户上下文
调用的方法名为:Sys.Services.AuthenticationService.login
登录状态:true


3、单击“注销”按钮
弹出框,信息:成功调用Sys.Services.AuthenticationService.logout


4、单击“保存Profile”按钮
通过Profile保存的属性的数量为:4


5、单击“读取Profile”按钮
通过Profile读取的属性的数量为:3
Age:27
Article Title:Article Title From Server
Article PublishTime:2007-07-12

作者:webabcd

[源码下载]







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.