以编程方式从 Umbraco 中的成员获取属性

发布于 2024-08-30 23:57:09 字数 212 浏览 6 评论 0原文

我认为这真的很简单,但是..

我们创建了一个用户和一个具有各种属性的成员类型 当我们尝试通过成员对象访问属性时,我们什么也没得到。

//成员 m 是当前用户,

例如。 属性 s = m.getProperty("首选用户名"); is null

m.getProperties 的计数为零..

我们是否错过了一些明显的东西?

I thought this would be really simple but ..

We've create a user and a member type with various properties
When we try to access the properties via the member object we got nothing.

//Member m is current User

eg.
Property s = m.getProperty("PreferdUserName");
is null

m.getProperties has a count of Zero..

have we missed something obvious?

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

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

发布评论

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

评论(5

对不⑦ 2024-09-06 23:57:09

会不会有拼写错误?

“PreferdUserName”可能希望是“PreferredUserName”。

除此之外它看起来是正确的。

Could there be a spelling error?

"PreferdUserName" may want to be "PreferredUserName".

Other than that it looks correct.

不寐倦长更 2024-09-06 23:57:09

最后,我求助于将成员属性存储在单独的数据库表中,无论如何,这更接近我的需要。
我认为这与我使用自定义 msbuild 任务从外部 umbraco 创建 memberType 的方式有关。

In the end i resorted to storing member properties in a separate db table, which anyhow is closer to what i need.
I presume it had something to do with the way I created the memberType from outside umbraco using a custom msbuild task.

缘字诀 2024-09-06 23:57:09

您可以创建自己的类并扩展 ProfileBase。下面的代码将公开您在 Umbraco 中创建的属性。例如 umbraco 别名是“first_name”。

[SettingsAllowAnonymous(false)]
public string FirstName
{
    get
    {
        var o = base.GetPropertyValue("first_name");
        if (o == DBNull.Value)
        {
            return string.Empty;
        }
        return (string)o;
    }
    set
    {
        base.SetPropertyValue("first_name", value);
    }
}

然后您可以访问像这样的属性...

string firstName = ((MemberProfile)HttpContext.Current.Profile).FirstName;

有关如何设置这一切的更多信息可以在此处查看:

http://www.aaron-powell.com/posts/2010-04-07-umbraco-members-profiles.html

You could create your own class and extend ProfileBase. The code below will expose the properties that you have created within Umbraco. e.g. umbraco alias is 'first_name'.

[SettingsAllowAnonymous(false)]
public string FirstName
{
    get
    {
        var o = base.GetPropertyValue("first_name");
        if (o == DBNull.Value)
        {
            return string.Empty;
        }
        return (string)o;
    }
    set
    {
        base.SetPropertyValue("first_name", value);
    }
}

Then you can access properties like so...

string firstName = ((MemberProfile)HttpContext.Current.Profile).FirstName;

More info about how to set this all up can be seen here:

http://www.aaron-powell.com/posts/2010-04-07-umbraco-members-profiles.html

不气馁 2024-09-06 23:57:09

如果您需要获取 Umbraco 中当前用户以外的其他人的成员详细信息并拥有他们的用户名,这可能会对其他人有所帮助。

var TheirUsername = "s12345";

Member MemberFind = new Member(Convert.ToInt32(Membership.GetUser(***TheirUsername***).ProviderUserKey));

//now use this value

var NameOfUser = MemberFind.Text;

var EmailAddress = MemberFind.Email;

This might help someone else, if you need to get member details for someone other than the current user in Umbraco and have their Username.

var TheirUsername = "s12345";

Member MemberFind = new Member(Convert.ToInt32(Membership.GetUser(***TheirUsername***).ProviderUserKey));

//now use this value

var NameOfUser = MemberFind.Text;

var EmailAddress = MemberFind.Email;
猫九 2024-09-06 23:57:09

尝试

Property s = m.getProperty("PreferdUserName").value;

如果仍然不起作用,请查看这篇关于成员属性的精彩文章

http://legacy.aaron-powell.com/blog/july-2009/umbraco-member-profiles.aspx

Try

Property s = m.getProperty("PreferdUserName").value;

If that still doesn't work, then check out this great post about member properties

http://legacy.aaron-powell.com/blog/july-2009/umbraco-member-profiles.aspx

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