gpt4 book ai didi

c# - 我如何使用 Profilebase 类?

转载 作者:行者123 更新时间:2023-11-30 13:42:30 24 4
gpt4 key购买 nike

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

如何从 dort_islem 类(class)看到 ilk_sayi?问候....

最佳答案

您缺少一些实现细节。

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

关于c# - 我如何使用 Profilebase 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2889158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com