Permissions on Profile Widget
I'm currently working on a project where I need to display single user profiles on a couple of public pages. I've dropped a Profile widget on a page and customized the widget to my needs by setting it to Read mode only and setting it to display a single user.
It works perfectly when I'm logged in, but when not logged in, it just displays the text: "You are not logged in.". I thought this would be pretty easy to fix by altering the permissions, but I just can't seem to figure out how make the widget visible to anonymous users. Is this by design and do I need to create my own custom widget?
Thanks in advance for your replies!
Hello Rein,
Anonymous users can't view profiles by implementation. However, there is a workaround that you can use. For this, you will have to:
1)Create a C# Library Project in the Solution of your Project solution (I named it ProfileWidgetOR)
2) Add references to the following assemblies:
System.Web
System.Web.Extensions
Telerik.Sitefinity
Telerik.Sitefinity.Resources
Telerik.Sitefinity.Model
Telerik.Sitefinity.Utilities
Telerik.Sitefinity.MigrationContracts
Telerik.Web.Design
Telerik.Web.UI
3)Create a Class (mine is name Class1.cs for simplicity) and paste this code into it and Build:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Telerik.Microsoft.Practices.EnterpriseLibrary.Logging;
using
Telerik.Sitefinity.Configuration;
using
Telerik.Sitefinity.Forms.Model;
using
Telerik.Sitefinity.Modules.Forms;
using
Telerik.Sitefinity.Modules.Forms.Web.UI;
using
Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
using
Telerik.Sitefinity.Services;
using
Telerik.Sitefinity.Web.UI.Fields;
using
Telerik.Sitefinity.Security.Web.UI;
using
Telerik.Sitefinity.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI;
using
Telerik.Sitefinity.Modules.UserProfiles.Web.UI;
using
Telerik.Sitefinity.Web.UI.ContentUI.Contracts;
namespace
ProfileWidgetOR
public
class
Class1 : UserProfileDetailReadView
public
override
string
LayoutTemplatePath
get
var userProfileViewHost = (UserProfileView)
this
.Host;
if
(
this
.IsUserAuthenticated() || (userProfileViewHost.DisplayCurrentUser.HasValue))
string
templatePath =
null
;
if
(
this
.Definition !=
null
)
templatePath =
this
.Definition.TemplatePath;
if
(
string
.IsNullOrEmpty(templatePath))
return
this
.DefaultLayoutTemplatePath;
return
templatePath;
else
if
(
this
.ProfileViewDefinition ==
null
|| String.IsNullOrEmpty(
this
.ProfileViewDefinition.NoUserTemplatePath))
return
UserProfileDetailReadView.noUserLayoutTemplatePath;
else
return
this
.ProfileViewDefinition.NoUserTemplatePath;
set
base
.LayoutTemplatePath = value;
public
override
string
TemplateKey
get
var userProfileViewHost = (UserProfileView)
this
.Host;
if
(
this
.IsUserAuthenticated() || (userProfileViewHost.DisplayCurrentUser.HasValue))
string
templateKey =
null
;
if
(
this
.Definition !=
null
)
templateKey =
this
.Definition.TemplateKey;
return
templateKey;
else
return
this
.NotLoggedTemplateKey;
set
base
.TemplateKey = value;
Hi Svetoslav,
Thank you for your answer. I have one more question though.
I need to override the settings of the auto-generated details page, so that also anonymous users can view the profile details. How can I achieve the same functionality as your solution above for the details page of the profile?
Thanks in advance for your help!
Rein
Hi Rein,
The ProfileList widget uses the same DetailsView that is used by the SingleUser Widget. This means that you can use the same class and it will work perfectly for the details page of your ProfileList widget. Just go to
Administration >> Settings >> Advanced >> ContentView >> Controls >>FrontendSingleProfile >> Views >> FrontendUsersList >> UserProfilesFrontendDetailsRead and set the ViewType property to be have the same value as the previous one (ProfileWidgetOR.Class1).