asp.net 中的自定义成员资格提供程序中的 createuser 成员需要自定义参数

发布于 2024-08-27 10:50:34 字数 150 浏览 4 评论 0原文

我想自定义 createuser() 方法 Membership Provider 中的参数,

实际上,我有自己的数据存储,用于具有不同数据(包括用户名、密码)的用户。

但是,createuser() 不适合我的数据

任何人都可以帮助我!

I want to customize the parameter in createuser() method Membership Provider,

Actually, i have my own data store for users with different data including username,password.

but, the createuser() is not suite with my data

Any one can help me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩套路吗 2024-09-03 10:50:34

你可以做这样的事情。

using System;

namespace SampleApplication.Models
{
    using System.Web.Security;

    public class SampleMembershipUser : MembershipUser
    {
        public int UserLevelId { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string ApplicationName { get; set; }

        public Guid UserId { get; set; }

        public TASMembershipUser(
            string providername,
            string username,
            object providerUserKey,
            string email,
            string passwordQuestion,
            string comment,
            bool isApproved,
            bool isLockedOut,
            DateTime creationDate,
            DateTime lastLoginDate,
            DateTime lastActivityDate,
            DateTime lastPasswordChangedDate,
            DateTime lastLockedOutDate,
            int userLevelId,
            string firstName,
            string lastName,
            string applicationName,
            Guid userId) :
            base(
                providername,
                username,
                providerUserKey,
                email,
                passwordQuestion,
                comment,
                isApproved,
                isLockedOut,
                creationDate,
                lastLoginDate,
                lastActivityDate,
                lastPasswordChangedDate,
                lastLockedOutDate)
        {
            UserLevelId = userLevelId;
            FirstName = firstName;
            LastName = lastName;
            ApplicationName = applicationName;
            UserId = userId;
        }
    }
}

You can do something like this.

using System;

namespace SampleApplication.Models
{
    using System.Web.Security;

    public class SampleMembershipUser : MembershipUser
    {
        public int UserLevelId { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string ApplicationName { get; set; }

        public Guid UserId { get; set; }

        public TASMembershipUser(
            string providername,
            string username,
            object providerUserKey,
            string email,
            string passwordQuestion,
            string comment,
            bool isApproved,
            bool isLockedOut,
            DateTime creationDate,
            DateTime lastLoginDate,
            DateTime lastActivityDate,
            DateTime lastPasswordChangedDate,
            DateTime lastLockedOutDate,
            int userLevelId,
            string firstName,
            string lastName,
            string applicationName,
            Guid userId) :
            base(
                providername,
                username,
                providerUserKey,
                email,
                passwordQuestion,
                comment,
                isApproved,
                isLockedOut,
                creationDate,
                lastLoginDate,
                lastActivityDate,
                lastPasswordChangedDate,
                lastLockedOutDate)
        {
            UserLevelId = userLevelId;
            FirstName = firstName;
            LastName = lastName;
            ApplicationName = applicationName;
            UserId = userId;
        }
    }
}
病毒体 2024-09-03 10:50:34

只要您的提供程序是唯一正在使用的提供程序,您就根本不需要通过 ASP.NET 调用 CreateUser 方法。只需在任何地方创建该方法并正常调用即可。

As long as your provider is the only one in use, you don't need to call your CreateUser method through ASP.NET at all. Just create the method anywhere and call it normally.

悲念泪 2024-09-03 10:50:34

迈克尔是对的,只是认为我会添加一些资源来帮助我完成这项任务:

来自 Microsoft 的优秀资源:

如何:实现自定义会员资格用户

上面链接中提到的另一个要记住的关键事情是,一旦完成创建自定义会员资格的工作user 和像 CreateUser 这样的方法的重载是您调用 Membership.CreateUser 的地方,您需要将其转换为自定义会员资格提供程序,例如:

((CustomMembershipProvider)Membership.Provider).CreateUser(p1,p2 etc...)

Michael is correct just thought that I would add some resources that helped me to undertake this task:

Great resource from Microsoft:

How to: Implement a Custom Membership User

The other key thing to remember that is mentioned in the above link is that once you have done the work to create custom membership user and overloads for your methods like CreateUser is that where you call Membership.CreateUser you need to cast this to your custom membership provider like:

((CustomMembershipProvider)Membership.Provider).CreateUser(p1,p2 etc...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文