ProfileProvider 重写问题。。。

bhtfg538 2008-08-30 11:48:32
我自己定义了一个
MyProfile 类继承自ProfileProvider
Config 是这样定义的
<anonymousIdentification enabled="true"/>
<profile defaultProvider="ProfileConnection">
<providers>
<clear/>
<add name="ProfileConnection" connectionStringName="ProfileConnection" type="Profile.WaWaProfileProvider" applicationName="WaWa Beta 1.0"/>
</providers>
<properties>
<clear/>
<add name="AccountInfo" type="Models.Account" provider="ProfileConnection" allowAnonymous="true" />
</properties>
为什么 IDE 里面就是不提示ProfileCommon 下的Profile 属性
ProfileConnection 是<connectionStrings>下的 某连接
Models.Account是Model 下的Account 实体

连接没有问题

不知道是什么原因

贴出自己的Profile
public sealed class WaWaProfileProvider : ProfileProvider
{
// Get an instance of the ProfileDAL using the ProfileDALFactory,though you can Config the Web.Config to Change Reflection
private static readonly IProfileDAL.IProfileProvider dal = ProfileFactory.DataAccess.CreatePetShopProfileProvider();
// Private members
private const string ERR_INVALID_PARAMETER = "Invalid Profile parameter:";
private const string PROFILE_ACCOUNT = "Account";//Account Information
private static string applicationName = "WaWa Beta 1.0";
#region "ProfileProvider"
/// <summary>
/// Retrieve Application Name
/// </summary>
public override string ApplicationName
{
get
{
return applicationName;
}
set
{
applicationName = value;
}
}
/// <summary>
/// Initial Function From ProfileBase
/// </summary>
/// <param name="name">Set a Friendly Name</param>
/// <param name="config">Name/Value Collection</param>
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
throw new ArgumentNullException("config");

if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "WaWa Custom Profile Provider");
}

if (string.IsNullOrEmpty(name))
name = "WaWaProfileProvider";

if (config["applicationName"] != null && !string.IsNullOrEmpty(config["applicationName"].Trim()))
applicationName = config["applicationName"];

base.Initialize(name, config);

}
/// <summary>
/// Retrieve SettingsPropertyValueCollection of Profile Property Value
/// </summary>
/// <param name="context">SettingsContext(Hashtable instance,Get a key/value Collection for Profile R/W)</param>
/// <param name="collection"></param>
/// <returns></returns>
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
{
string username = (string)context["UserName"];
bool isAuthenticated = (bool)context["IsAuthenticated"];

SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

foreach(SettingsProperty prop in collection) {
SettingsPropertyValue pv = new SettingsPropertyValue(prop);

switch(pv.Property.Name) {
case PROFILE_ACCOUNT:
if(isAuthenticated)
pv.PropertyValue = GetAccountInfo(username);
break;
default:
throw new ApplicationException(ERR_INVALID_PARAMETER + " name.");
}
svc.Add(pv);
}
return svc;
}
private object GetAccountInfo(string username)
{
return dal.GetAccountInfo(username, applicationName);
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{

string username = (string)context["UserName"];
CheckUserName(username);
bool isAuthenticated = (bool)context["IsAuthenticated"];
int uniqueID = dal.GetUniqueID(username, isAuthenticated, false, ApplicationName);
if (uniqueID == 0)
uniqueID = dal.CreateProfileForUser(username, isAuthenticated, ApplicationName);

foreach (SettingsPropertyValue pv in collection)
{
if (pv.PropertyValue != null)
{
switch (pv.Property.Name)
{
case PROFILE_ACCOUNT:
if (isAuthenticated)
SetAccountInfo(uniqueID, (Account)pv.PropertyValue);
break;
default:
throw new ApplicationException(ERR_INVALID_PARAMETER + " name.");
}
}
}
}
private static void SetAccountInfo(int uniqueID, Account account)
{
dal.SetAccountInfo(uniqueID, account);
}
private static bool DeleteProfile(string username)
{
CheckUserName(username);
return dal.DeleteProfile(username, applicationName);
}

private static void CheckUserName(string userName)
{
if (string.IsNullOrEmpty(userName) || userName.Length > 256 || userName.IndexOf(",") > 0)
throw new ApplicationException(ERR_INVALID_PARAMETER + " user name.");
}
/// <summary>
/// Delete Profiles
/// </summary>
/// <param name="profiles">A System.Web.Profile.ProfileInfoCollection of information about profiles that are to be deleted.</param>
/// <returns>The number of profiles deleted from the data source.</returns>
public override int DeleteProfiles(ProfileInfoCollection profiles)
{
int deleteCount = 0;

foreach (ProfileInfo p in profiles)
if (DeleteProfile(p.UserName))
deleteCount++;

return deleteCount;
}

/// <summary>
///
/// </summary>
/// <param name="usernames"></param>
/// <returns></returns>
public override int DeleteProfiles(string[] usernames)
{
int deleteCount = 0;
foreach (string user in usernames)
if (DeleteProfile(user))
deleteCount++;

return deleteCount;
}


...全文
267 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaizuo2010 2011-07-14
  • 打赏
  • 举报
回复
跟 PETSHOP 4 代码很相似,可以参考那个
sevenisme777 2009-03-10
  • 打赏
  • 举报
回复
跟 PETSHOP 4 代码很相似,可以参考那个
bhtfg538 2008-09-01
  • 打赏
  • 举报
回复
为什么 Profile 本地数据连接 可以
链接服务器就有问题了
连接没有出问题

其他都没有动
bin 下面也有
Anlige 2008-08-31
  • 打赏
  • 举报
回复
.net???~
banditi225 2008-08-30
  • 打赏
  • 举报
回复
是方法的提示出不来吗
编程有钱人了 2008-08-30
  • 打赏
  • 举报
回复
up
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
谢谢你了
问题还没解决
郁闷了好一阵子
还不知道是什么错误啊
lifelz888 2008-08-30
  • 打赏
  • 举报
回复
看看,有点头痛呵.
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
大家来看下帮帮忙
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
UP 一个
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
/// <summary>
/// profiles deleted from the data source for the special authentication options and datetime
/// </summary>
/// <param name="authenticationOption">One of the System.Web.Profile.ProfileAuthenticationOption values, specifying whether anonymous, authenticated, or both types of profiles are deleted.</param>
/// <param name="userInactiveSinceDate">A System.DateTime that identifies which user profiles are considered inactive. If the System.Web.Profile.ProfileInfo.LastActivityDate value of a user profile occurs on or before this date and time, the profile is considered inactive.</param>
/// <returns>The number of profiles deleted from the data source.</returns>
public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
{
string[] userArray = new string[0];
dal.GetInactiveProfiles((int)authenticationOption, userInactiveSinceDate, ApplicationName).CopyTo(userArray, 0);

return DeleteProfiles(userArray);
}
public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{

CheckParameters(pageIndex, pageSize);

return GetProfileInfo(authenticationOption, usernameToMatch, null, pageIndex, pageSize, out totalRecords);
}

private static void CheckParameters(int pageIndex, int pageSize)
{
if (pageIndex < 1 || pageSize < 1)
throw new ApplicationException(ERR_INVALID_PARAMETER + " page index.");
}

private static ProfileInfoCollection GetProfileInfo(ProfileAuthenticationOption authenticationOption, string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
{

ProfileInfoCollection profiles = new ProfileInfoCollection();

totalRecords = 0;

// Count profiles only.
if (pageSize == 0)
return profiles;

int counter = 0;
int startIndex = pageSize * (pageIndex - 1);
int endIndex = startIndex + pageSize - 1;

DateTime dt = new DateTime(1900, 1, 1);
if (userInactiveSinceDate != null)
dt = (DateTime)userInactiveSinceDate;

foreach (CustomProfileInfo profile in dal.GetProfileInfo((int)authenticationOption, usernameToMatch, dt, applicationName, out totalRecords))
{
if (counter >= startIndex)
{
ProfileInfo p = new ProfileInfo(profile.UserName, profile.IsAnonymous, profile.LastActivityDate, profile.LastUpdatedDate, 0);
profiles.Add(p);
}

if (counter >= endIndex)
{
break;
}

counter++;
}

return profiles;
}
/// <summary>
///
/// </summary>
/// <param name="authenticationOption"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="totalRecords"></param>
/// <returns></returns>
public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
{
CheckParameters(pageIndex, pageSize);

return GetProfileInfo(authenticationOption, null, null, pageIndex, pageSize, out totalRecords);
}
public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
{

CheckParameters(pageIndex, pageSize);

return GetProfileInfo(authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
}

public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
{
CheckParameters(pageIndex, pageSize);

return GetProfileInfo(authenticationOption, null, null, pageIndex, pageSize, out totalRecords);
}

public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
{

int inactiveProfiles = 0;

ProfileInfoCollection profiles = GetProfileInfo(authenticationOption, null, userInactiveSinceDate, 0, 0, out inactiveProfiles);

return inactiveProfiles;
}

#endregion

}
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
救命帮忙啊
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
没有人会吗?
bhtfg538 2008-08-30
  • 打赏
  • 举报
回复
是 没有 Profile 属性

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧