WCF RIA 服务 (三十三)-- 身份验证、角色、个性化 4
2013-07-11 15:29
337 查看
如何:在RIA Services中允许个性化功能
使用个性化功能,我们可以为用户检索和保存属性。WCF RIA Services中的个性化功能建立在ASP.NET的个性化框架上。
我们只能在用户验证后检索或保存个性化属性。
配 置服务端项目
1. 在服务端项目中,打开Web.config文件。
2. 在段内,添加元 素。
3. 在元素内,添加个性化属性。下面示例如何创建个性化以及定义一个名为FriendlyName的属性。
[xhtml]
view plaincopyprint?
<system.web>
<authentication
mode="Forms"></authentication>
<profile
enabled="true">
<properties>
<add
name="FriendlyName">
</add>
</properties>
</profile>
</system.web>
从 客户端访问个性化属性
1. 在Silverlight客户端项目中,打开后台代码页面。
2. 在后台代码页面中,设置或检索当前WebContext实例的User对象上的个性化属性。
[c-sharp]
view plaincopyprint?
WebContext.Current.User.FriendlyName = "Mike";
使用个性化功能,我们可以为用户检索和保存属性。WCF RIA Services中的个性化功能建立在ASP.NET的个性化框架上。
我们只能在用户验证后检索或保存个性化属性。
配 置服务端项目
1. 在服务端项目中,打开Web.config文件。
2. 在段内,添加元 素。
3. 在元素内,添加个性化属性。下面示例如何创建个性化以及定义一个名为FriendlyName的属性。
[xhtml]
view plaincopyprint?
<system.web>
<authentication
mode="Forms"></authentication>
<profile
enabled="true">
<properties>
<add
name="FriendlyName">
</add>
</properties>
</profile>
</system.web>
4. 为验证服务打开包含User类的文件。 5. 在User类中,添加我们已在Web.config文件中添加过的个性化属性。 [c-sharp] view plaincopyprint? public partial class User : UserBase { public string FriendlyName { get; set; } } public partial class User : UserBase { public string FriendlyName { get; set; } }
从 客户端访问个性化属性
1. 在Silverlight客户端项目中,打开后台代码页面。
2. 在后台代码页面中,设置或检索当前WebContext实例的User对象上的个性化属性。
[c-sharp]
view plaincopyprint?
WebContext.Current.User.FriendlyName = "Mike";
通 过声明性语法,我们也可以检索个性化属性。示例如下: [xhtml] view plaincopyprint? <textblock text="{Binding Source={StaticResource WebContext},Path=User.FriendlyName}"> </textblock> <textblock text="{Binding Source={StaticResource WebContext},Path=User.FriendlyName}"> </textblock>
相关文章推荐
- WCF RIA 服务 (三十三)-- 身份验证、角色、个性化 4
- WCF RIA 服务 (三十三)-- 身份验证、角色、个性化 4
- Silverlight WCF RIA服务(三十三)身份验证、角色、个性化 4
- WCF RIA 服务 (三十五)-- 身份验证、角色、个性化 6
- WCF RIA 服务 (三十二)-- 身份验证、角色、个性化 3
- WCF RIA 服务 (三十)-- 身份验证、角色、个性化
- WCF RIA 服务 (三十一)-- 身份验证、角色、个性化 2
- WCF RIA 服务 (三十二)-- 身份验证、角色、个性化 3
- WCF RIA 服务 (三十五)-- 身份验证、角色、个性化 6
- WCF RIA 服务 (三十四)-- 身份验证、角色、个性化 5
- Silverlight WCF RIA服务(三十)身份验证、角色、个性化 1
- Silverlight WCF RIA服务(三十)身份验证、角色、个性化 1
- WCF RIA 服务 (三十四)-- 身份验证、角色、个性化 5
- Silverlight WCF RIA服务(三十一)身份验证、角色、个性化 2
- Silverlight WCF RIA服务(三十二)身份验证、角色、个性化 3
- Silverlight WCF RIA服务(三十一)身份验证、角色、个性化 2
- WCF RIA 服务 (三十)-- 身份验证、角色、个性化
- WCF RIA 服务 (三十二)-- 身份验证、角色、个性化 3
- WCF RIA 服务 (三十一)-- 身份验证、角色、个性化 2
- WCF RIA 服务 (三十四)-- 身份验证、角色、个性化 5