如何使用Profilebase类? [英] How can i use Profilebase class?
问题描述
我尝试使用asp.net的资料,我尽量给继承与ProfileBase
i try to use asp.net profile, i try to give inheritance with ProfileBase
public class dort_islem : ProfileBase
{
public int ilk_sayi { get; set; }
public int ikinci_sayi { get; set; }
}
<anonymousIdentification enabled="true"/>
<profile enabled="true" inherits="dort_islem">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="profiller"/>
</providers>
<properties>
<add name="ad" allowAnonymous="true" defaultValue="yusuf"/>
<add name="soy_ad" allowAnonymous="true"/>
<add name="sevdigi_renk" allowAnonymous="true" type="System.Drawing.Color" serializeAs="Binary" />
<group name="detaylar">
<add name="numara" type="Integer" allowAnonymous="true"/>
<add name="giris_tarihi" type="Date" allowAnonymous="true"/>
<add name="cinsiyet" allowAnonymous="true"/>
<add name="adres" allowAnonymous="true"/>
</group>
</properties>
</profile>
但如果我尝试使用这些codeS的Default.aspx:
but if i try to use these codes Default.aspx:
我怎样才能看到ilk_sayi从dort_islem类?商祺....
How can i see ilk_sayi from dort_islem class? Regards....
推荐答案
您缺少一个几个的实施细则。
You are missing a few implementation details.
using System.Web.Profile;
using System.Web.Security;
namespace VideoShow
{
public class UserProfile : ProfileBase
{
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
[SettingsAllowAnonymous(false)]
public string Description
{
get { return base["Description"] as string; }
set { base["Description"] = value; }
}
[SettingsAllowAnonymous(false)]
public string Location
{
get { return base["Location"] as string; }
set { base["Location"] = value; }
}
[SettingsAllowAnonymous(false)]
public string FavoriteMovie
{
get { return base["FavoriteMovie"] as string; }
set { base["FavoriteMovie"] = value; }
}
}
}
现在,我们需要挂钩,在web.config中的轮廓部分 - 注意,我已经包括在配置文件中声明继承=VideoShow.UserProfile:
Now we need to hook that up in the profile section of web.config - notice that I've included inherits="VideoShow.UserProfile" in the profile declaration:
<profile inherits="VideoShow.UserProfile">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="VideoShowConnectionString"/>
</providers>
</profile>
做完这些,我可以抓住的自定义配置文件类的一个实例,并设置属性:
With that done, I can grab an instance of the custom profile class and set a property:
//Write to a user profile from a textbox value
UserProfile profile = UserProfile.GetUserProfile(currentUser.UserName);
profile.FavoriteMovie = FavoriteMovie.Text;
profile.Save();
从<一个href="http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx">http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx
这篇关于如何使用Profilebase类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!