sqlprofileProvider用法
2007-07-12 15:19
351 查看
做項目中發現微軟已經為開發人員做好了許多事情,profileProvider就是其中之一,它主要用于當前用戶(已注冊的或匿名用戶)個人的屬性,有人會問這些屬性可以定義在表中,為什么用profile,就是因為profile在不同的系統中可能有不設定值,所以是動態的,為了可以用最小的開發來實現及時性不高但變化相對快的設定而建制的。
SqlProfileProvider直接將property寫入數據庫或從數據庫中讀出。用它必須有以下几步:
1. 在web.config中有Profile的配置。
<system.web>
<anonymousIdentification enabled ="true "/>
<profile defaultProvider="sqlprovider1" enabled ="true " automaticSaveEnabled ="true" >
<providers>
<clear />
<add name="sqlprovider1"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="Login"
applicationName="Tuna"
description="for SampleApplication" />
</providers>
<properties>
<add name ="firstname" allowAnonymous ="true"/>
<add name ="lastname" allowAnonymous ="true"/>
</properties>
</profile>
</system.web>
2. 在需要使用profile的地點用如下語句調用:
SettingsPropertyValueCollection ppvc = ProfileManager.Provider.GetPropertyValues(HttpContext.Current.Profile.Context, ProfileBase.Properties);
string firstname = ppvc["firstname"].PropertyValue as string ;
ppvc["lastname"].PropertyValue = "abc";
ProfileManager.Provider.SetPropertyValues(HttpContext.Current.Profile.Context, ppvc);
3. 也可以在代碼中寫入config中沒有的屬性:
SettingsPropertyValueCollection ppvc = ProfileManager.Provider.GetPropertyValues(HttpContext.Current.Profile.Context, ProfileBase.Properties);
string firstname = ppvc["firstname"].PropertyValue as string ;
SettingsAttributeDictionary dictionary1 = new SettingsAttributeDictionary();
dictionary1.Add ("AllowAnonymous", true);
SettingsProperty sps = new SettingsProperty("Ext", typeof(string), ProfileManager.Provider, false, "default", SettingsSerializeAs.String, dictionary1, false, true);
SettingsPropertyValue sp = new SettingsPropertyValue (sps) ;
ppvc.Add(sp);
ppvc["Ext"].PropertyValue = "9999";
ProfileManager.Provider.SetPropertyValues(HttpContext.Current.Profile.Context, ppvc);
SqlProfileProvider直接將property寫入數據庫或從數據庫中讀出。用它必須有以下几步:
1. 在web.config中有Profile的配置。
<system.web>
<anonymousIdentification enabled ="true "/>
<profile defaultProvider="sqlprovider1" enabled ="true " automaticSaveEnabled ="true" >
<providers>
<clear />
<add name="sqlprovider1"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="Login"
applicationName="Tuna"
description="for SampleApplication" />
</providers>
<properties>
<add name ="firstname" allowAnonymous ="true"/>
<add name ="lastname" allowAnonymous ="true"/>
</properties>
</profile>
</system.web>
2. 在需要使用profile的地點用如下語句調用:
SettingsPropertyValueCollection ppvc = ProfileManager.Provider.GetPropertyValues(HttpContext.Current.Profile.Context, ProfileBase.Properties);
string firstname = ppvc["firstname"].PropertyValue as string ;
ppvc["lastname"].PropertyValue = "abc";
ProfileManager.Provider.SetPropertyValues(HttpContext.Current.Profile.Context, ppvc);
3. 也可以在代碼中寫入config中沒有的屬性:
SettingsPropertyValueCollection ppvc = ProfileManager.Provider.GetPropertyValues(HttpContext.Current.Profile.Context, ProfileBase.Properties);
string firstname = ppvc["firstname"].PropertyValue as string ;
SettingsAttributeDictionary dictionary1 = new SettingsAttributeDictionary();
dictionary1.Add ("AllowAnonymous", true);
SettingsProperty sps = new SettingsProperty("Ext", typeof(string), ProfileManager.Provider, false, "default", SettingsSerializeAs.String, dictionary1, false, true);
SettingsPropertyValue sp = new SettingsPropertyValue (sps) ;
ppvc.Add(sp);
ppvc["Ext"].PropertyValue = "9999";
ProfileManager.Provider.SetPropertyValues(HttpContext.Current.Profile.Context, ppvc);
相关文章推荐
- SQL PROFILE的用法
- SQL PROFILE的用法
- 让SQL Server Compact支持 Membership, Role and Profile provider
- 让SQL Server Compact支持 Membership, Role and Profile provider
- ASP.NET 用户配置 Part.2(SQLProfileProvider)
- Profile 详解之 Provider 和 基本用法
- SQL中DATALENGTH用法
- SQL中EXISTS的用法
- SQL 中 with as 用法(转)
- SQL Case的用法
- sql中isnull()用法
- sql:inner join,left join,right join,full join的用法及含义
- LinQ to SQL用法详解
- SQL中的join的详细用法!inner join,full outer join,left join,right jion
- SQL中IN和EXISTS用法的区别,sql中exists,not exists的用法
- Union all的用法实例sql
- 详解C#中SqlParameter的作用与用法
- SQL查找XML里面符合某个条件的用法
- sql中的 IF 条件语句的用法
- SQL中count用法