简体   繁体   English

ASP .Net成员资格和成员资格类别

[英]ASP .Net membership and membership class

Couple of questions: 几个问题:

I have a database i created under the app_data folder. 我在app_data文件夹下创建了一个数据库。 Is there anyway to associate this database with an EXISTING aspnetdb which is also under the same folder? 无论如何,是否将此数据库与同样位于同一文件夹下的现有aspnetdb关联? If so could anyone guide me? 如果可以的话,有人可以指导我吗?

If not then what would be the best way to create my own database under the APP_CODE folder which would also utilise asp .net membership? 如果不是,那么在APP_CODE文件夹下创建自己的数据库(也将利用asp .net成员身份)的最佳方法是什么? By that i mean i could check for username and roles theyre in, in code (If User.IsinRole("........") etc and use the icon inside the project to open the membership page and add/modify/delete users too? 我的意思是,我可以在代码中检查用户名和角色(如果使用User.IsinRole(“ ........”)等),并使用项目内的图标打开成员资格页面并添加/修改/也删除用户?

Thanks 谢谢

You can create a MembershipProvider. 您可以创建一个MembershipProvider。 An example is available at code project, Custom Membership Providers 代码项目“ 自定义成员资格提供程序”中提供了一个示例

All you need to do is change the connection string to point to the same database for both. 您需要做的就是将连接字符串更改为指向两者的相同数据库。 Of course, you will have to copy the schema from one to the other, and any data you need. 当然,您将必须将架构以及所需的任何数据从一个复制到另一个。

You can create your custom Membership Provider because you have custom dataBase, not the generated dataBase with aspnet_regsql. 您可以创建自定义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(); }
    }
}

You register your memberShip provider 您注册您的会员船舶供应商

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM