[英]ASP .Net membership and membership class
幾個問題:
我在app_data文件夾下創建了一個數據庫。 無論如何,是否將此數據庫與同樣位於同一文件夾下的現有aspnetdb關聯? 如果可以的話,有人可以指導我嗎?
如果不是,那么在APP_CODE文件夾下創建自己的數據庫(也將利用asp .net成員身份)的最佳方法是什么? 我的意思是,我可以在代碼中檢查用戶名和角色(如果使用User.IsinRole(“ ........”)等),並使用項目內的圖標打開成員資格頁面並添加/修改/也刪除用戶?
謝謝
您可以創建一個MembershipProvider。 代碼項目“ 自定義成員資格提供程序”中提供了一個示例
您需要做的就是將連接字符串更改為指向兩者的相同數據庫。 當然,您將必須將架構以及所需的任何數據從一個復制到另一個。
您可以創建自定義Membership Provider
因為您具有自定義數據庫,而沒有使用aspnet_regsql生成的數據庫。
public class CustomMembershipProvider : MembershipProvider
{
public override MembershipUser CreateUser(string username,
string password, string email, string passwordQuestion,
string passwordAnswer, bool isApproved,
object providerUserKey, out MembershipCreateStatus status)
{
throw new NotImplementedException();
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
throw new NotImplementedException();
}
public override bool ValidateUser(string username, string password)
{
throw new NotImplementedException();
}
public override int MinRequiredPasswordLength
{
get { throw new NotImplementedException(); }
}
public override bool RequiresUniqueEmail
{
get { throw new NotImplementedException(); }
}
}
您注冊您的會員船舶供應商
<connectionStrings>
<add name="ApplicationServices"
connectionString="Server=your_server;Database=your_db;
Uid=your_user_name;Pwd=your_password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="CustomMembership.Models.CustomMembershipProvider"
connectionStringName="AppDb"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.