November Happy Hour will be moved to Thursday December 5th.

Admin Plugin return 404

Vote:
 

Hi!

I've searched far and wide across the web for a solution, but being completely new to Episerver and the world of CMS, I just can't seem to get it right.
I manage to get my plugin to show up in the admin tools menu, and up until yesterday it actually crashed visually for me. Now I didn't get anything until I actually opened the console and it seems to return "the server responded with a status of 404 ()". Any ideas how to fix this?

Here's my controller that I try to get to fire:

  [GuiPlugIn(
        Area = PlugInArea.AdminMenu,
        Url = "~/modules/SecurityTxtHandler/SecurityTxtAdmin",
        DisplayName = "Manage security.txt content",
        Description = "Tool to edit security.txt")]


    [Authorize(Roles = "CmsAdmins")]
    public class SecurityTxtAdminController : Controller
    {
        protected ISecurityContentService SecurityService { get; set; }
        public SecurityTxtAdminController()
        {
            SecurityService = new SecurityContentService();
        }
        public ActionResult Index()
        {
            var model = new SecurityTxtViewModel();

            var listAllHosts = GetAllHosts();
            model.SiteList = listAllHosts;

            if (listAllHosts.Count > 0)
                model.SecurityContent = SecurityService.GetSecurityContent(listAllHosts.First().Value);

            return View(model);
        }

And my initialization:

    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class CustomRouteInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            RouteTable.Routes.MapRoute("SecurityTxtRoute", "security.txt", new { controller = "SecurityTxt", action = "Index" });
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
        public void Preload(string[] parameters)
        {
        }
    }
#264989
Oct 13, 2021 11:34
Vote:
 

From memory I think the value you pass on the second param of the MapRoutes need to match the Url in your GuiPlugin declaration.

For example you see in this post https://blog.novacare.no/creating-episerver-admin-plugins-using-mvc/ both the URL and the Route param match. Also the URL isn't a path to a file it's just a unique path to identify your module. So I would change both values to "custom-plugins/securitytxt"

#264990
Edited, Oct 13, 2021 12:05
Vote:
 

One other point, this way of creating plugins has been removed for the .NET 5 version (CMS 12) so if you have any expectation of upgrading in the future I'd create it using a menu item in the editor as show here https://world.optimizely.com/blogs/mark-stott/dates/2021/8/extending-the-admin-interface-in-optimizely-cms-12/ which works for now and for CMS 12 (.NET 5)

#264991
Edited, Oct 13, 2021 12:08
Mark Stott - Oct 13, 2021 15:03
Thank you for the blog reference Scott :)
Scott Reed - Oct 13, 2021 15:04
Haha no worries, I've shared it a few times :p
Vote:
 

Thanks for the help Scott, I managed to get the URL right in the end, now it's pointing to the right controller and action. Evidently the blog post (which I have read a few times) was a big help, and there's a small "/" at one of the url-pointers that I missed. Working fine now! 

#265085
Oct 14, 2021 13:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.