How to create an EPiServer Admin/Edit Plug-ins using MVC?

Vote:
 

Hi,

I found this page about creating admin pages:

http://world.episerver.com/Blogs/Paul-Smith/Dates1/2011/8/Creating-EPiServer-AdminEdit-Plug-ins-using-MVC/

I followed every step of the tutorial but i cant get it working. I do see an item named 'My MVC Admin Plugin' under tools but when i click on it i end up with an empty page. I am building this in the latest version of the Alloy MVC sample site.

This is what i have done so far:

  • I created a folder ~/Modules/Alloy under the root of the project
  • I created a controller in this folder (notice i made a small adjustment to the Area because i dont want it to appear in the config tab):
    using System.Web.Mvc;
    using EPiServer.PlugIn;
    
    namespace EPiServer.Templates.Alloy.Modules.Alloy
    {
        [GuiPlugIn(
            Area = EPiServer.PlugIn.PlugInArea.AdminMenu,
            Url = "/modules/Alloy/MyAdminPlugin/Index",
            DisplayName = "My MVC Admin Plugin")]
        public class MyAdminPluginController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
        }
    }
  • Next I opened the web.config in the root of the project and added the lines from the tutorial.
     
        
          
            
              
            
          
        
        
      
  • Now i build the project and went to the admin page. I got an error about the assembly. This is where i got stuck because i dont really understand what it is. So eventually I end up removing the section. and now i can see my admin page.
  • When I click on the admin page 'My MVC Admin Plugin' i got an empty page. I put some breakpoints in the controller and the Index method is never called. When i check the url of the frame it is: http://sneek:17000/modules/Alloy/MyAdminPlugin/Index

Can somebody please help me because I am really stuck here. I assume the problem is with the assembly because thats the part where i dont know what i am doing exactly.

Thanks!

#109771
Oct 14, 2014 15:11
Vote:
 

Hi,

The two most helpful blog posts related to this would be:

http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2014/4/Adding-custom-views-to-your-content/

http://world.episerver.com/Blogs/Duong-Nguyen/Dates/2013/12/Custom-views-and-plugin-areas-in-EPiServer-75/

#109779
Oct 14, 2014 17:42
Vote:
 

I would suggest you verify that you have the correct assembly name in your web.config, especially if your module lives inside of your project.

In one of my recent EPiServer 7.5 test sites, where the module lives directly under "~/modules/", this is what my <episerver.shell> looks like:

  <episerver.shell>
    <publicModules rootPath="~/modules/" autoDiscovery="Modules">
      <add name="MY_MODULE_NAME">
        <assemblies>
          <add assembly="MY_PROJECT_NAME" />
        </assemblies>
      </add>
    </publicModules>
    <protectedModules rootPath="~/EPiServer/">
      <add name="Shell" />
      <add name="CMS" />
      <add name="EPiServer.Packaging.UI" />
    </protectedModules>
  </episerver.shell>
#109780
Oct 14, 2014 17:44
Vote:
 

First of all thanks for the quick response but i still have an empty page (404 error) :-(.

My web.config now looks like this:

episerver.shell>
      <publicModules rootPath="~/modules/" autoDiscovery="Modules">
        <add name="MyAdminPlugin">
          <assemblies>
            <add assembly="EPiServer.Templates.Alloy.Mvc" />
          </assemblies>
        </add>
      </publicModules>
    <protectedModules rootPath="~/episerver/"></protectedModules>
  </episerver.shell>

My module, which is located at ~/Modules/Alloy/MyAdminPluginController.cs containts the following code:

using System.Web.Mvc;
using EPiServer.PlugIn;

namespace EPiServer.Templates.Alloy.Modules.Alloy
{
    [GuiPlugIn(
        Area = PlugInArea.AdminMenu,
        Url = "/modules/Alloy/MyAdminPlugin/Index",
        DisplayName = "Webshop bestellingen")]
    public class MyAdminPluginController : Controller
    {
        public string Index()
        {
            return "Hello Admin!";
        }

    }
}

Other info about my project is:

Project name: AlloyMvc
Assembly name: EPiServer.Templates.Alloy.MvcDefault namespace: EPiServer.Templates.Alloy

I dont understand why episerver doesnt create a route to my guiplugin controller.

#109796
Oct 15, 2014 11:01
Vote:
 

Try switching your assembly to:

<episerver.shell>
      <publicModules rootPath="~/modules/" autoDiscovery="Modules">
        <add name="MyAdminPlugin">
          <assemblies>
            <add assembly="EPiServer.Templates.Alloy" />
          </assemblies>
        </add>
      </publicModules>
    <protectedModules rootPath="~/episerver/"></protectedModules>
</episerver.shell>
#109801
Oct 15, 2014 12:25
Vote:
 

If i switch my assembly to that i get an error:

Server Error in '/' Application. Could not load file or assembly 'EPiServer.Templates.Alloy' or one of its dependencies. The system cannot find the file specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'EPiServer.Templates.Alloy' or one of its dependencies. The system cannot find the file specified.

#109808
Oct 15, 2014 12:54
Vote:
 

Thanks for all the help! I got it working now :-).

The correct web.config setting for me was:

<episerver.shell>
    <publicModules rootPath="~/modules/" autoDiscovery="Modules">
      <add name="Alloy">
        <assemblies>
          <add assembly="EPiServer.Templates.Alloy.Mvc"/>
        </assemblies>
      </add>
    </publicModules>
    <protectedModules rootPath="~/episerver/"/>
  </episerver.shell>

I made a couple of mistakes, most of them because i didnt really understand what i was configuring here. What helped for me was this article explaining how the episerver.shell section works:

Configuring episerver.shell Section

The problem for me was the name Alloy and the correct assembly EPiServer.Templates.Alloy.Mvc.

Let me give a simple example that worked for me for people with the same issue:

  • Create a new Episerver MVC Alloy sample project
  • Create a directory under the root ~/modules/Alloy/. The last part of this directory can be everything. I use alloy now as an example.3.
  • Now create a new class in this directory (MyAdminPluginController.cs):
    using System.Web.Mvc;
    using EPiServer.PlugIn;
    
    namespace EPiServer.Templates.Alloy.Modules.Alloy
    {
        [GuiPlugIn(
            Area = PlugInArea.AdminMenu,
            Url = "/modules/Alloy/MyAdminPlugin/Index",
            DisplayName = "Webshop bestellingen")]
        public class MyAdminPluginController : Controller
        {
            public string Index()
            {
                return "Hello Admin!";
            }
    
        }
    }
    The URL is very important! This URL tells EPiServer were it can find your controller.
  • Now open your web.config in the root of your project. Search for the section
    <episerver.shell>
  • Make it look like this:
    <episerver.shell>
        <publicModules rootPath="~/modules/" autoDiscovery="Modules">
          <add name="Alloy">
            <assemblies>
              <add assembly="EPiServer.Templates.Alloy.Mvc"/>
            </assemblies>
          </add>
        </publicModules>
        <protectedModules rootPath="~/episerver/"/>
      </episerver.shell>
    Important is here the <add name="Alloy">. Remember that you named the directory Alloy in ~/modules/Alloy.
    If you named it different then you need to put that name here.
    Next the assembly is important. For me this is <add assembly="EPiServer.Templates.Alloy.Mvc"/> but this could be different for you.
    JUst right-click on your project and open properties. Next check your application Assembly Name. You should use that one.
  • Thats it. Build your project and go to your admin page. You should see a "Hello Admin" message.
#109860
Oct 16, 2014 9:31
Vote:
 

You can also just register a normal MVC route. I have updated my original blog post with this information. http://world.episerver.com/Blogs/Paul-Smith/Dates1/2011/8/Creating-EPiServer-AdminEdit-Plug-ins-using-MVC/

#112244
Oct 25, 2014 6:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.