我總是使用我自己的代碼來創建登錄和註冊,但使用成員資格應該可以爲我在以下項目中編程這些東西節省大量時間。定製會員實施
現在我發現了許多關於實現自己的自定義成員資格的教程,其中一些教程與其他教程不同。而且我很難理解實施簡單的自定義成員資格實施的最佳解決方案。
對於這個項目,我只需要添加一些額外的用戶信息,如streetname,郵編等
什麼目前我所做的是:
public class CustomMembershipUser : MembershipUser
{
public CustomMembershipUser(
string providerName,
string name,
object providerUserKey,
string email,
string passwordQuestion,
string comment,
bool isApproved,
bool isLockedOut,
DateTime creationDate,
DateTime lastLoginDate,
DateTime lastActivityDate,
DateTime lastPasswordChangedDate,
DateTime lastLockoutDate
)
: base(providerName, name, providerUserKey, email, passwordQuestion,
comment, isApproved, isLockedOut, creationDate, lastLoginDate,
lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
{
}
// Add additional properties
public string Streetname { get; set; }
public string Postcode { get; set; }
}
public abstract class CustomMembershipProvider : MembershipProvider
{
public override MembershipUser GetUser(string username, bool userIsOnline)
{
// get data logic
var user = new CustomMembershipUser(
"CustomMembershipProvider",
"naam",
"1",
"[email protected]",
"",
"",
true,
false,
DateTime.Now,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue) { Streetname = "Test", Postcode = "Test2"};
return user;
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer,
bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
var user = new CustomMembershipUser(
"CustomMembershipProvider",
"naam",
"1",
"[email protected]",
"",
"",
true,
false,
DateTime.Now,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue) { Streetname = "Test", Postcode = "Test2" };
status = MembershipCreateStatus.Success;
return user;
}
}
這是最好的解決方案我的自定義會員資格還是有更好的選擇?
我還沒有測試過,所以我不知道這是否有效。
我使用MVC 4