我自己定义了一个
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;
}
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;
}
/// 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 }
链接服务器就有问题了
连接没有出问题
~
其他都没有动
bin 下面也有