Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pronto 61 posts 172 karma points
    Jul 07, 2014 @ 16:30
    pronto
    0

    Adding a new section with Application Startup

    Hi All,

    I am new to extending Umbraco and I am specifically trying to add a new section to an Umbraco 7 installation. I have found some tutorials that mention running a snippet of code at Umbraco startup, which has lead me to the 
    'application startup' process, which I am also unfamiliar with.

    From what I can gather, I need to add this code to my global.asax file, but whatever I write in there (be it from a tutorial or Umbraco documentation) I always get a server error with "The content in the application file is not valid." so I must be doing something wrong!

    So, I found the following code on http://antao.github.io/development/2013/12/29/creating-umbraco-7-custom-section.html but now I don't know where it should go and what else I need to configure:
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
      var sectionService = applicationContext.Services.SectionService;
      sectionService.MakeNew("My awesome section", "myAwesome", "awesome-icon", 10);
    }
    Can anyone point my in the right direction?
    Many thanks,
    pronto
  • Mike Chambers 635 posts 1252 karma points c-trib
    Jul 07, 2014 @ 16:56
  • pronto 61 posts 172 karma points
    Jul 08, 2014 @ 10:08
    pronto
    0

    Hi Mike,

    Thanks for the reply! I did find that tutorial as well but unfortunately for me it assumes that I know my way around the application startup process, which I don't! The following sentence from that article says the following: 

    The first thing I’ll need to do is to create a class that implements the IApplication-interface so that Umbraco will initialize this class on start up. 

     But how do I create this class? Where does it go etc...?

    Many thanks,
    pronto

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jul 08, 2014 @ 10:24
    Mike Chambers
    100

    easiest way, if you don't know your way around creating a class library with c# and producing a dll, is to create a .cs file in the app_code folder which will get JIT compiled at runtime.

    contents are something like this just to get the section added... (not fully tested, but should I think point you in the right direction...)

    (CustomSection.cs)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.businesslogic;
    using umbraco.interfaces;
    
    [Application("CustomSection", "CustomSection", "icon-car", 15)]
    public class CustomSectionApplication : IApplication { }
    
        

     

  • pronto 61 posts 172 karma points
    Jul 08, 2014 @ 10:48
    pronto
    0

    Hi Mike,

    That's perfect, thanks a million! I might actually be able to follow that guide now, wish me luck!

    pronto 

  • Darren Clark 52 posts 249 karma points
    Jul 08, 2014 @ 16:42
    Darren Clark
    0

    Hi Folks,

    I am trying to add a new section to an umbraco 7 installation using the SectionService.MakeNew, yes i can see that it adds a new entry to the application.config. but the section never appears in the backend when you log back in.

    Am i missing a trick here????

    Instead of using the application startup code to register the new section could i not just add it manually to the application.config?

    Regards Darren

  • Darren Clark 52 posts 249 karma points
    Jul 08, 2014 @ 17:34
    Darren Clark
    0

    Hi Again,

    If you add a a new record into the umbracoUser2App database table then the section appears. But is does not appear as an item in the edit user page until you manually add the record, surely if you add the new section then it should appear as a new unticked checkbox in the edit user page.

    Regards Darren

  • pronto 61 posts 172 karma points
    Jul 08, 2014 @ 17:37
    pronto
    0

    Hi Darren,

    Did you enable the custom section for your User? If you go to Users > YourUser, your custom section is probably unticked! If that fails, maybe restart your application but I'm afraid I can't be of much more help!

    pronto

  • Darren Clark 52 posts 249 karma points
    Jul 09, 2014 @ 19:14
    Darren Clark
    0

    Hi Pronto,

    The custom section was not visible, looked like it was a caching issue.

    Cheers

  • Tarik 8 posts 78 karma points
    Sep 18, 2017 @ 21:24
    Tarik
    0

    I found other solution using code downloaded by webmatrix using the following steps.

    Umbraco version: 7.5.4 1

    steps:

    applications.config

    <?xml version="1.0" encoding="utf-8"?>
    <applications>
      <add alias="content" name="Content" icon="traycontent" sortOrder="0" />
      <add alias="media" name="Media" icon="traymedia" sortOrder="1" />
      <add alias="settings" name="Settings" icon="traysettings" sortOrder="2" />
      <add alias="developer" name="Developer" icon="traydeveloper" sortOrder="3" />
      <add alias="users" name="Users" icon="trayuser" sortOrder="4" />
      <add alias="member" name="Members" icon="traymember" sortOrder="5" />
      <add alias="forms" name="Forms" icon="icon-umb-contour" sortOrder="6" />
      <add alias="translation" name="Translation" icon="traytranslation" sortOrder="7" />
      <add alias="car" name="Car" icon="icon-car" sortOrder="15" />
    </applications>
    

    Dashboard.config

    ...
        <section alias="Car">
        <areas>
          <area>car</area>
        </areas>
        <tab caption="Start it">
          <control>
            views/dashboard/developer/redirecturls.html
          </control>
        </tab>
      </section>
    </dashBoard>
    

    MemberSection Users section Result enter image description here

  • Marcio Goularte 374 posts 1346 karma points
    Sep 18, 2017 @ 21:58
    Marcio Goularte
    0
     public class Startup : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
            if (ApplicationContext.Current != null)
                {
                    // check if section existes
                    Section section = ApplicationContext.Current.Services.SectionService.GetByAlias("SectionName");
                    if (section == null)
                    {
                        ApplicationContext.Current.Services.SectionService.MakeNew("SectionName", "SectionAlias", "icon-wand");
    
                        //Permissions to Admin : maybe change with the new version 7.7.0
                        ApplicationContext.Current.Services.UserService.AddSectionToAllUsers(Constants.SectionAlias, 0);
                    }
                }
    
            }              
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft