The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
In this blog post I will show you how you could display additional user information in a Sitefinity forum post. This user information should be available as a custom field in the users’ profile.
Prerequisites:
Created custom field in the users’ profile (for example: JobPosition)
Code explanation:
1. We need to create a class for our custom field and inherit from Literal:
public
class
CustomField : Literal
{
// we will implement our logic here
}
private
string
ownerId =
null
;
private
string
myField =
null
;
public
string
OwnerId
{
get
{
return
ownerId;
}
set
{
ownerId = value;
}
}
public
string
MyField
{
get
{
return
myField;
}
set
{
myField = value;
}
}
protected
override
void
CreateChildControls()
{
// get the current identity
var identity = ClaimsManager.GetCurrentIdentity();
// get information about the user from the properties of the ClaimsIdentityProxy object
var userId = identity.UserId;
// Get user and profile Manager
UserProfileManager profileManager = UserProfileManager.GetManager();
UserManager userManager = UserManager.GetManager();
// Get current user
User user = userManager.GetUser(userId);
// Get the current user’s profile
SitefinityProfile profile =
null
;
if
(user !=
null
)
{
profile = profileManager.GetUserProfile<SitefinityProfile>(user);
}
// Get the value we are interested to
var mySearchedField = profile.GetValue(myField).ToString();
// This text will be displayed when we call the property.
Text = mySearchedField;
// Call the base method
base
.CreateChildControls();
}
<%@ Register TagPrefix=" myTagPrefix " Namespace="SitefinityWebApp" Assembly="SitefinityWebApp" %>
<
myTagPrefix:CustomField
Text='<%# Eval("Content") %>' OwnerId='<%# Eval("Owner")%>' MyField='JobPosition' runat="server" />
You could download the complete code example of CustomField.
Svetoslav Manchev is a Technical Support Officer at Telerik since 2013.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.