惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - L.Zhang

.Net Remoting RMI框架 自己开发连接池 JDBC访问数据库 MyEclipse下开发Web Service 使用传统的XMLHttpRequest发出Ajax请求 XML CDATA XPath 数据库操作的sql脚本 直接选择排序 直接插入排序 气泡排序 Builder 生成器模式(创建型模式) Abstract Factory 抽象工厂模式(创建型模式) Factory Method 工厂方法模式(创建型模式) Singleton单件模式(创建型模式) 服务端如何使用Session 让服务端返回xml 用Get方式访问
使用Profile Service
L.Zhang · 2007-11-01 · via 博客园 - L.Zhang

//客户端代码

<head runat="server">
    
<title>Profile Service</title>
    
<script language="javascript" type="text/javascript">
        
        
//保存profile
        function saveProfiles()
        {   
            
//获取属性对象
            var properties = Sys.Services.ProfileService.properties;
            properties.Name 
= $get("txtName").value;
            properties.Age 
= parseInt($get("txtAge").value, 10);
            properties.Address.City 
= $get("txtCity").value;
            properties.Address.PostalCode 
= $get("txtPostalCode").value;
            
            
/*
            Sys.Services.ProfileService.save(propertyNames, // 需要保存的Profile名,null表示全取
                                             saveCompletedCallback, // 保存成功的回调函数
                                             failedCallback, // 加载失败的回调函数
                                             userContext // 可以随意指定的上下文对象
                                             ); 
*/
            
            
//写入
            Sys.Services.ProfileService.save(
                
null,
                saveCompleted);
        }
        
        
//保存成功回调函数
        function saveCompleted()
        {
            $get(
"message").innerHTML = "Profile Saved";
        }
        
        
//读取profile
        function loadProfiles()
        {
            
/*Sys.Services.ProfileService.load(propertyNames, // 需要加载的Profile名,null表示全取
                                               loadCompletedCallback, // 加载成功的回调函数
                                               failedCallback, // 加载失败的回调函数
                                               userContext // 可以随意指定的上下文对象
                                               );
*/
            Sys.Services.ProfileService.load(
                
null,
                loadCompleted);
        }
        
        
/*
        function loadCompletedCallback(number, // 本次加载的Profile数量
                                       userContext, // 用户随意指定的上下文对象
                                       methodName // 即"Sys.Services.ProfileService.load"
                                      )
        
*/
        
//读取成功回调函数
        function loadCompleted()
        {
            
//获取属性对象
            var properties = Sys.Services.ProfileService.properties;
            
//判断profile是否存在
            if (properties.Age)
            {   
//读取profile
                $get("txtName").value= properties.Name;
                $get(
"txtAge").value= properties.Age;
                $get(
"txtCity").value = properties.Address.City;
                $get(
"txtPostalCode").value = properties.Address.PostalCode;
                
                $get(
"message").innerHTML = "Profile Loaded";
            }
            
else
            {
                $get(
"txtName").value= "";
                $get(
"txtAge").value= "";
                $get(
"txtCity").value = "";
                $get(
"txtPostalCode").value = "";
                
                $get(
"message").innerHTML = "No Profile";
            }
        }
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
        
<asp:ScriptManager ID="ScriptManager1" runat="server">
            
<ProfileService LoadProperties="Address.City, Address.PostalCode, Name, Age" />
        
</asp:ScriptManager>
        
        
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
        
<asp:Button ID="btnLogIn" runat="server" Text="Login" OnClick="btnLogin_Click" />
        
<asp:Button ID="btnLogout" runat="server" Text="Logout" OnClick="btnLogout_Click" />
        
<hr />
        
        Name: 
<input type="text" id="txtName" /><br />
        Age: 
<input type="text" id="txtAge" /><br />
        Email: 
<input type="text" id="txtEmail" /><br />
        City: 
<input type="text" id="txtCity" /><br />
        Street: 
<input type="text" id="txtStreet" /><br />
        Postal Code: 
<input type="text" id="txtPostalCode" /><br />
        
        
<div id="message" style="color:Red;"></div><br />
        
        
<input type="button" value="Show" onclick="loadProfiles()" />
        
<input type="button" value="Save" onclick="saveProfiles()" />
    
</form>
</body>

//服务器端函数,用于登陆,登出

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SetAuthCookie(
this.txtUserName.Text, false);
    }
protected void btnLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
    }

//WebConfig配置
出于安全性的考虑,ASP.NET AJAX的Profile Service在默认情况下不会开放Profile的访问权限

  <system.web.extensions>
    
<scripting>
      
<webServices>
        
<profileService enabled="true"
                        readAccessProperties
="Name, Age, Email, Address.City, Address.Street, Address.PostalCode"
                        writeAccessProperties
="Name, Age, Email, Address.City, Address.Street, Address.PostalCode" />
      
</webServices>
    
</scripting>
  
</system.web.extensions>

    <profile enabled="true" automaticSaveEnabled="true" defaultProvider="SqlProvider">
      
<providers>
        
<clear />
        
<add name="SqlProvider"
             type
="System.Web.Profile.SqlProfileProvider"
             connectionStringName
="ProfileDatabase" 
             applicationName
="ProfileSample" 
             description
="Sample for ASP.NET profile and Profile Service" />
      
</providers>
      
<properties>
        
<add name="Name" type="System.String"/>
        
<add name="Email" type="System.String" />
        
<add name="Age" type="System.Int32" />
        
<group name="Address">
          
<add name="City" type="System.String" />
          
<add name="Street" type="System.String" />
          
<add name="PostalCode" type="System.String" />
        
</group>
      
</properties>
    
</profile>