Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

c# - How can i use Profilebase class?

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>

but if i try to use these codes Default.aspx: alt text

How can i see ilk_sayi from dort_islem class? Regards....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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; }
        }
    }
}

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();

from http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...