【问题标题】:How can i use Profilebase class?我如何使用 Profilebase 类?
【发布时间】:2011-02-22 18:25:14
【问题描述】:

我尝试使用 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:

我如何从 dort_islem 课程中看到 ilk_sayi?问候....

【问题讨论】:

    标签: c# asp.net .net-3.5 visual-studio-2010


    【解决方案1】:

    您缺少几个实现细节。

    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 的配置文件部分 - 请注意,我在配置文件声明中包含了 inherits="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

    【讨论】:

    • @Phsika - 我建议您下载一个工作示例并检查它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 2019-04-13
    相关资源
    最近更新 更多