+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Object reference not set error.

Object reference not set error.

17 posts, 0 answered
  1. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    16 Sep 2010
    Link to this post
    Hi,

    I'm implementing custom security for my intra-site modules as I require the access permission right upto the view level. The data structure, as well as the business logic implemented for the same (using the provider model) is also custom. The security model is working perfectly except for a small problem though.

    The problem is, if a user does not have permissions to any of the views in a module, my code does not add them in the command panel, eventually keeping the command panel empty. When I click on the Modules tab, if my module is the first module to be displayed, I get a run-time error (as mentioned in the attached screenshot). In contrast to this, if the user has an access permission to even one view in the module, the page gets displayed perfectly (screenshot 2).

    I'm not able to figure out where exactly is the problem.

    Thanks,
    Saumitra
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Sep 2010
    Link to this post
    Hello Saumitra,

    The BreadCrumb control uses Repeater and it looks like that the container which contains the control is null or the repeater is not found. You could try mapping

    [Sitefinity_3_7_standard_ExternalTemplates]\Sitefinity\Admin\ControlTemplates\Common\AdminBreadcrumb.ascx and see during your request what is going wrong.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    17 Sep 2010
    Link to this post
    Hi Ivan,

    I've mapped the breadcrumb control to the external template. But the template does not have a code behind. And also the markup has just an empty repeater control. How would I be able to check where is the request going wrong?

    Thanks,
    Saumitra
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Sep 2010
    Link to this post
    Hello Saumitra,

    You can create a code behind of the template and subscribe for ItemDataBound.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    17 Sep 2010
    Link to this post
    Hi Ivan,

    Somehow the template mapping at my end is not working as per expected. I followed the steps as explained in this article: http://www.sitefinity.com/devnet/kb/sitefinity-3-x/how-to-map-a-view-to-an-external-template-in-sitefinity-3-6-or-later.aspx. But the application is still referring to Telerik.Cms.Web.UI.Backend.BackendBreadcrumb. Following is the code in the Telerik.Sitefinity.Configuration.ControlsConfig.xml file in App_Data\Configuration folder:
    <?xml version="1.0" encoding="utf-8"?>
    <controlsConfig>
      <viewMap>
        <!--This template defines the layout of Breadcrumb control in Control Panel.-->
        <viewSettings hostType="Telerik.Cms.Web.UI.Backend.BackendBreadcrumb" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Common/AdminBreadcrumb.ascx" />
      </viewMap>
    </controlsConfig>

    Also the template has been placed in the ~\Sitefinity\Admin\ControlTemplates\Common folder. By the way, the template does not have a resource file as mentioned in the article above.

    What can be the problem?

    Thanks,
    Saumitra
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Sep 2010
    Link to this post
    Hello Saumitra,

    Attached is a sample project with the breadcrumb template mapped, a code file created where you can add logic in the item data bound event of the repeater.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    20 Sep 2010
    Link to this post
    Hi,

    I've done the template mapping exactly as you've demonstrated in the sample. The result is still the same. Its throwing the same run-time error and that too from the Telerik.Cms.Web.UI.BackendBreadCrumb class instead of my mapped template. I even stopped and started my website post mapping the template.

    I'm still not getting where am I going wrong

    Thanks,
    Saumitra
  8. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    25 Sep 2010
    Link to this post
    Hi,

    Any updates on this issue ?

    Thanks,
    Saumitra
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Sep 2010
    Link to this post
    Hi Saumitra,

    Could you send a sample project that illustrates this issue? Can you reproduce it with one of the default modules with the same permissions set up? Have you tried to follow our suggestions and see what is going wrong in ItemDataBound event of the Breadcrumb Repeater?

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    27 Sep 2010
    Link to this post
    Hi,

    1) Yes, I've followed your suggestions but as I'd said ealier, the ItemDataBound event does not get triggered at all.

    2) I'm not sure whether I can try and reproduce the same error with the default modules, as I've implemented a custom security model from scratch. Secondly, the error occurs only if none of the DEFAULT modules are visible to the logged in user.

    3) How do I attach my code with this reply? I guess, the forums allow only image files to be attached.

    Thanks,
    Saumitra
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Sep 2010
    Link to this post
    Hi Saumitra,

    You can provide us with an external link from where we could download all necessary files to reproduce this issue.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    28 Sep 2010
    Link to this post
    Hi Ivan,

    You can download the files from http://saumitra.idealake.com/customerorders/CustomerOrders_Latest.zip. I've included following type of files in the archive:

    1) All the code (class files) in App_Code that takes care of the implementation of the custom security.
    2) Usercontrol for setting the permissions (/Sitefinity/Admin/ControlTemplates/Modules/Masters/Permissions.ascx).
    3) External template for BreadCrumb as suggested by you, with ItemDataBound event subscribed to(/Sitefinity/Admin/ControlTemplates/Common/AdminBreadcrumb.ascx).
    4) Admin.master.cs, where logic has been implemented to ensure that the module does not get displayed if none of the views inside has "view" permissions for the current user.

    Please ignore all the commented code in the App_code class files and please let me know if I need to provide anything else.

    Thanks,
    Saumitra
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Sep 2010
    Link to this post
    Hello Saumitra,

    With the files you have provided I am getting object reference from moduleList.SelectedItem DropDown list inside Sitefinity/Admin/ControlTemplates/Modules/Masters/Permissions.ascx
    The list does not get populated from MastersDataProvider.cs and all tables are empty - dsModules.Tables[0].Rows.Count returns null.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    28 Sep 2010
    Link to this post
    Hi Ivan,

    Very sorry to skip the database scripts with the earlier file. Please find them at http://saumitra.idealake.com/customerorders/PermissionScripts.zip.

    Thanks,
    Saumitra
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Sep 2010
    Link to this post
    Hi Saumitra,

    The problem is that you are not adding the views inside MastersControlPanel and there is no CommandItems for the command panel which is used as bread crumb datasource. To fix the issue you have to add a dummy "Accessed Denied" view inside CustomersView and MastersPermissionsView. Generally, if the user can give permissions he/she should be able to see the CustomersView so you do not have to check whether there is AllowView for CustomersView

    namespace CustomerOrders.Modules.Masters
    {
        public class CustomersView : ViewModeControl<MastersControlPanel>
        {
     
            protected override void CreateViews()
            {
                ModulePermissions permissions;
                ModuleManager manager = new ModuleManager();
     
                permissions = manager.GetPermissions("Manage Customers");
                if (permissions.AllowView)
                {
                    AddView("CustomersListView", "~/Sitefinity/Admin/ControlTemplates/Modules/Masters/CustomersListView.ascx", "View Customers", "Displays all customers", "all", null);
     
                }
                else
                {
                    AddView("AccessDenied", "~/Sitefinity/Admin/ControlTemplates/Modules/Masters/AccessDenied.ascx", "Access Denied", "AccessDenied", "all", null);
                }
     
            }
        }
    }

    You can check for permissions inside MastersControlPanel, but first you need to check whether "AllowView" is set for MastersPermissionsView, then you will automatically load CustomersView. if there is no access to MastersPermissionsView check the permissions set for CustomersView. If the access to both of them is denied you do not have to create a RadTab in the menu.

    The RadTabStrip  is bound inside Sitefinity/Admin.master. It datasource is created by using our permissions logic and you cannot hide the "Masters" tab using your implementation. You have to check whether the RadTagStip contains a tab "Masters", then check the permissions for the current user and rebind the control.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    29 Sep 2010
    Link to this post
    Hi Ivan,

    I understood the explaination given by you, except for the last sentence - "You have to check whether the RadTagStip contains a tab "Masters", then check the permissions for the current user and rebind the control". I wanted to know how do I do that using my implementation. Especially the rebinding part.

    Thanks,
    Saumitra
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Sep 2010
    Link to this post
    Hello Saumitra,

    You can get RadTab generic collection inside Sitefinity\Admin\Admin.master.cs by using MainMenu_DataBound event.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
17 posts, 0 answered