More in this section

Forums / Developing with Sitefinity / Override providername for contentview

Override providername for contentview

2 posts, 1 answered
  1. Webteam
    Webteam avatar
    28 posts
    Registered:
    30 Nov 2009
    20 Jan 2010
    Link to this post
    Hi,

    I am trying to set the provider at runtime (based off of a users login role) for all contentview based controls.  From what I can tell the easiest the way to do this would be to add a class to app_code that overrides contentview and point to this class in controlsconfig.xml.

    Can someone let me know
    1.) if this approach would work, and
    2.) how to setup controlsconfig to override the contentview display, I have looked through a number of other posts and can succesfully override the creating of new content but not the display of it. 

    thanks,



  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Jan 2010
    Link to this post
    Hi David Desjardins,

    You do not have to modify ControlsConfig file. You have to override ItemListTemplatePath and SingleItemTemplate path in your custom class. Then override ProviderName property and set your custom provider

    sample code

    public override string ItemListTemplatePath
       {
           get
           {
               return "~/Sitefinity/Admin/ControlTemplates/GenericContent/ContentViewItemList.aspx;
           }
           
       }
     
       public override string SingleItemTemplatePath
       {
           get
           {
               return "~/Sitefinity/Admin/ControlTemplates/GenericContent/ContentViewSingleItem.ascx";
           }
           
       }
     
       public override string ProviderName
       {
           get
           {
               if(UserManager.IsCurrentUserInRole("administrators"))
                   return "CustomProvider";
               return _providerName;
           }
           set
           {
               this._providerName = value;
           }
       }
       private string _providerName;


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
2 posts, 1 answered