Assigning new members to groups automatically ..error when following instructions

Hi Umbraco community,

Good day! I need to have Member-only pages/Restricted access and I’m following the instructions here until right at the end. Attached screenshots. I’m getting an error when inserting the Macros in the rich text editor. I’m not really a developer and new to Visual Studio. How am I suppose to add a new .cs file ? I have just created a .cs file and named it as myclass.cs and its placed in the same folder as Program.cs. Thanks.






regards
Jamie

Hi Jamie :slightly_smiling_face:

There seems to a lot going on here.

Since it looks like you’re using Umbraco 13, I would highly recommend you do not develop new features based on the old “Macro” system.
As stated on the documentation for them indicates that they’re being removed very soon.

“Macros and Partial View Macros will be removed in the next version. Consider using Partial Views or Blocks in Rich Text Editor.”

If you want to build pages dynamically as an editor, then I would advise you to look into building Block Lists or Block Grids.

These property editor will require some development knowledge, but should be compatible with many newer versions of Umbraco.
You can probably reuse some if not most of your existing razor code (The HTLM with the BeginUmbraoForm).

When building UI in Umbraco, you should aim to place all .cshtml files directly in the “Views” folder or a given sub-folder, based on which type of template it represents.
An example of this is a Block List component which should be place in Views-->Partials-->blocklist-->Components

As for the C# code, you would generally name the files, (eg. myclass.cs) the same as the class name inside the file.
Now looking at your code, it seems like you make a C# Controller, which ideally should be place in a “Controllers” or “Api” folder for better clarity.
This however, is not a requirement.

Another thing that isn’t necessarily a requirement is the namespace of the class.
I can see this is not following your project structure, which can cause confusion and problems that are hard to debug.
Namespaces in C# should generally follow the project->folder structure.

See these two example, one for a top level class and one in a sub-folder:


I know I didn’t directly answer your question or provide a solution, but I would really encourage you to consider not using Macros or adding components etc. to the Rich Text Editor(RTE).

Regards
Seb

Thanks Seb, will read through this.

So what umbraco version do you recommend me using ? Can I use the latest version, Umbraco 15 so there are less problems ?

Hi @webdesigner4theworld :slightly_smiling_face:

You can use Umbraco 13 until the next LTS comes out, no problem in that.
But you should not implement code using the Macro system in Umbraco.

1 Like