Как я могу использовать класс Profilebase? - PullRequest
3 голосов
/ 22 мая 2010

я пытаюсь использовать профиль asp.net, я пытаюсь передать наследование с помощью 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>

но если я попытаюсь использовать эти коды Default.aspx: альтернативный текст http://i47.tinypic.com/zn5v60.gif

Как я могу увидеть ilk_sayi из класса dort_islem? С уважением ....

1 Ответ

10 голосов
/ 22 мая 2010

Вам не хватает нескольких подробностей реализации.

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" в объявлении профиля:

<profile inherits="VideoShow.UserProfile">
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="VideoShowConnectionString"/>
  </providers>
</profile>

После этого я могу получить экземпляр пользовательского класса профиля и установить свойство:

//Write to a user profile from a textbox value
UserProfile profile = UserProfile.GetUserProfile(currentUser.UserName);
profile.FavoriteMovie = FavoriteMovie.Text;
profile.Save();

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...