More in this section

Forums / Developing with Sitefinity / Creating custom control of user profile

Creating custom control of user profile

7 posts, 0 answered
  1. Olga
    Olga avatar
    6 posts
    Registered:
    03 Feb 2011
    06 Jul 2011
    Link to this post
    I'm creating a simple control of user profile as 
    UserProfileView.ascx
    <%@ Control Language="C#" %>
     
    <%@ Register Assembly="Telerik.Web.UI, Version=2011.1.413.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register Assembly="Telerik.Sitefinity, Version=4.1.1501.0, Culture=neutral, PublicKeyToken=b28c218413bdf563" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
     
     
    <sitefinity:Message
                runat="server"
                ID="message"
                ElementTag="div"
                RemoveAfter="30000"
                FadeDuration="10" />
     
    <asp:Label ID="Label1" Text="<%$ Resources:UserProfileResources, FullName %>" runat="server" AssociatedControlID="FullName" Font-Bold="True"/><br />
    <asp:TextBox ID="FirstName" runat="server" Width="100%"/>
    <asp:RequiredFieldValidator ID="FullNameRequired" runat="server" CssClass="sfError" Display="Dynamic"
                                ControlToValidate="FullName" SetFocusOnError="true">
                                <strong><asp:Literal ID="fnRequired" runat="server" Text="<%$ Resources:UserProfileResources, FullNameRequired %>"></asp:Literal></strong>
                            </asp:RequiredFieldValidator>
     
     
    <br /><br />

    UserProfile.cs
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Model;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Localization;
     
    namespace UserProfileControl
    {
        public class UserProfile : SimpleView
        {
            private const string layoutTemplateName = "UserProfileControl.Resources.ControlTemplates.UserProfileView.ascx";
     
            protected override string LayoutTemplateName
            {
                get
                {
                    return layoutTemplateName;
                }
            }
             
            protected override HtmlTextWriterTag TagKey
            {
                get
                {
                    return HtmlTextWriterTag.Div;
                }
            }
            protected virtual string FullName
            {
                get
                {
                    return this.Container.GetControl<TextBox>("FullName", true).Text;
                }
            }
               protected Message Message
            {
                get
                {
                    return this.Container.GetControl<Message>("message", true);
                }
            }
     
            protected override void OnInit(System.EventArgs e)
            {
                base.OnInit(e);
                Res.RegisterResource<UserProfileResources>();
            }
            protected override void InitializeControls(GenericContainer container)
            {
                UserManager manager = UserManager.GetManager();
     
                this.Container.GetControl<TextBox>("FullName", true).Text = HttpContext.Current.User.Identity.Name as string;
            }
        }
    }


    UserProfileResources.cs
    using Telerik.Sitefinity.Localization;
    using Telerik.Sitefinity.Localization.Data;
     
    namespace UserProfileControl
    {
        [ObjectInfo("UserProfileResources", ResourceClassId = "UserProfileResources")]
        public class UserProfileResources : Resource
        {
            [ResourceEntry("FullName",
                Value = "FullName")]
            public string FullName
            {
                get
                {
                    return this["FullName"];
                }
            }
     
            [ResourceEntry("FullNameRequired",
                Value = "Full name required")]
            public string FullNameRequired
            {
                get
                {
                    return this["FullNameRequired"];
                }
            }
       }
    }


    Whan I add control on page, get 

    Application id class 'Telerik.OpenAccess.RT.OID.GuidIdentity' must have field: 'public System.Guid id'

    Stack Trace: 

    [OpenAccessException: Application id class 'Telerik.OpenAccess.RT.OID.GuidIdentity' must have field: 'public System.Guid id']
       DynamicModule.ns.Wrapped_OpenAccessMetaDataProvider_614fe6b1dfa947db878ae870adfb28df.Initialize(String providerName, NameValueCollection config, Type managerType) +197
       Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, Type providerType, ExceptionPolicyName policy, ManagerBase`1 manager) +1250
       Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, ExceptionPolicyName policy, ManagerBase`1 manager) +63
       Telerik.Sitefinity.Data.ManagerBase`1.SetProvider(String providerName, String transactionName) +297
       Telerik.Sitefinity.Data.ManagerBase`1..ctor(String providerName, String transactionName) +131
       Telerik.Sitefinity.Data.Metadata.MetadataManager..ctor() +12
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
       System.Activator.CreateInstance() +103
       Telerik.Sitefinity.Data.ManagerBase`1.GetManager(String providerName, String transactionName) +80
       Telerik.Sitefinity.Services.SystemManager.Initialize() +171
       Telerik.Sitefinity.Abstractions.Bootstrapper.RegisterRoutes(RouteCollection routes) +263
       Telerik.Sitefinity.Abstractions.Bootstrapper.Bootstrap() +239
       Telerik.Sitefinity.Web.SitefinityHttpModule.Init(HttpApplication context) +116
       System.Web.Routing.UrlRoutingModule.System.Web.IHttpModule.Init(HttpApplication application) +10
       System.Web.HttpApplication.InitModulesCommon() +166
       System.Web.HttpApplication.InitModules() +46
       System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +715
       System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +283
       System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +104
       System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327

    Is there any solution for this issue?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jul 2011
    Link to this post
    Hi Olga,

    The problem seems to be caused by

    UserManager manager = UserManager.GetManager();

    Does removing the line fix the error? If you call this line from another control or a page, do you get errors?


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Olga
    Olga avatar
    6 posts
    Registered:
    03 Feb 2011
    07 Jul 2011
    Link to this post
    Removing the line doesn't fix error, but adding the line is cause of error at another control.
    I change line 
    this.Container.GetControl<TextBox>("FullName", true).Text = HttpContext.Current.User.Identity.Name as string;

    to
    this.Container.GetControl<TextBox>("FullName", true).Text = "Name";

    I get another error

    Invalid resource name "UserProfile.Resources.ControlTemplates.UserProfileView.ascx" for assembly "UserProfile, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or empty template.

    Stack Trace: 

    [ArgumentException: Invalid resource name "UserProfile.Resources.ControlTemplates.UserProfileView.ascx" for assembly "UserProfile, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or empty template.]
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration, Boolean addChildrenAsDirectDescendants) +777
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +436
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +1056
       Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +119
       Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +21
       Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +46
       System.Web.UI.Control.EnsureChildControls() +122
       System.Web.UI.Control.PreRenderRecursiveInternal() +49
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6877


    How to resolve this problem and get information about current user?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jul 2011
    Link to this post
    Hello Olga,

    Please use VirtualPathProvider to register the control template. Since Sitefinity 4.1 we introduced VPP

    http://www.sitefinity.com/blogs/slavoingilizov/posts/11-04-18/taking_advantage_of_the_virtual_path_provider_in_sitefinity_4_1.aspx

    so one way is registering the template through global.asax as the post above shows.

    The other way is to set a prefix in your private const string used for the template like "~/SfSamples", then this prefix should be registered in the configuration (itefinity>> Administration >> Settings >> Advanced >> VirtualPathSettings )together with the assembly where the template is defined


    public override string LayoutTemplatePath
            {
                get
                {
                    return layoutTemplatePath;
                }
                
            }

            protected override string LayoutTemplateName
            {
                get
                {
                    return null;
                }
            }

    private const string layoutTemplatePath = "~/SfSamples/Telerik.Sitefinity.Samples1.Resources.MyCustomTemplate.ascx";

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Olga
    Olga avatar
    6 posts
    Registered:
    03 Feb 2011
    08 Jul 2011
    Link to this post
    I registry VirtualPathProvider (screenshot attach) and rewrite UserProfile

    namespace UserProfile
    {
        public class UserProfile : SimpleView
        {
            public override string LayoutTemplatePath
            {
                get
                {
                    return layoutTemplatePath;
                }
            }
            protected override string LayoutTemplateName
            {
                get
                {
                    return null;
                }
            }
     
            private const string layoutTemplatePath = "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx";
     
            protected override HtmlTextWriterTag TagKey
            {
                get
                {
                    return HtmlTextWriterTag.Div;
                }
            }
     
            protected virtual string FullName
            {
                get
                {
                    return this.Container.GetControl<TextBox>("FullName", true).Text;
                }
            }
            protected Message Message
            {
                get
                {
                    return this.Container.GetControl<Message>("message", true);
                }
            }
            protected override void OnInit(System.EventArgs e)
            {
                base.OnInit(e);
                Res.RegisterResource<UserProfileResources>();
            }
             
             
            protected override void InitializeControls(GenericContainer container)
            {
                this.Container.GetControl<TextBox>("FullName", true).Text = "admin";
            }
        }
    }

    and get error 

    Cannot find template "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx".


    Stack Trace: 

    [ArgumentException: Cannot find template "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx".]
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration, Boolean addChildrenAsDirectDescendants) +864
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +436
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +1056
       Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +119
       Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +21
       Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +46
       System.Web.UI.Control.EnsureChildControls() +122
       System.Web.UI.Control.PreRenderRecursiveInternal() +49
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Control.PreRenderRecursiveInternal() +204
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6878

    Where am I mistaken? Have you sample control using virtual path?

     
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jul 2011
    Link to this post
    Hello Olga,

    Is you template build as an embedded resource?

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Olga
    Olga avatar
    6 posts
    Registered:
    03 Feb 2011
    08 Jul 2011
    Link to this post
    Yes,sure.  Template build as embedded resource
7 posts, 0 answered