Skip to main content
Solved

Unable to modify the Web.Config file settings using customization plug-in


Forum|alt.badge.img

Hello Everyone,

We are trying to update the Web.Config file settings through the customization plug-in but getting below error.

I have followed same code written by @smarenich  from the below link but not working in the 22 R1 version.

Link: https://asiablog.acumatica.com/2016/11/site-configuration-using-customization.html

Also, attached customization package for your reference.

Can anyone help me on this?

 

 

Best answer by markusray17

For Azure integration you can just send the necessary values to Acumatica(or your partner) and they can update the Web.config(as Dimitrii said). And I wouldn’t recommend using a customization plugin unless you really know what you are doing, particularly on a SaaS instance. Errors with the config file will prevent your instance from starting.

 

In regards to the code snippet webconfig is never defined. Looking at the git history that seems to just be a typo, “webconfig” should be “file”. He changed it from modifying web.config to modifying packages.config but did not update the variable.

Original Code

String webconfig = File.ReadAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "web.config"));

webconfig = webconfig.Replace("<add key=\"ReminderVisible\" value=\"false\" />", "<add key=\"ReminderVisible\" value=\"true\" />");

File.WriteAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "web.config"), webconfig);

Updated Code

String file = File.ReadAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"));

//This should be file = file.Replace
file = webconfig.Replace("</packages>", 
         "<package id=/"Newtonsoft.Json/" version=/"6.0.8/" targetFramework=/"net451/" /></packages>");

File.WriteAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"), file);

 

View original
Did this topic help you find an answer to your question?

8 replies

  • Freshman II
  • 3 replies
  • June 11, 2022

would need to see the source to offer up much help. But reads like you have a casing issue. e.g. webconfig may need to be WebConfig. Common issue in uncompiled code files is getting casing correct.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 45 replies
  • June 11, 2022

Here is the source code:

 

using System;
using PX.Data;
using System.Collections.Specialized;
using Customization;
using System.Web.Security;
using System.IO;
using PX.Common;
using PX.Web.Customization;


namespace ChangeWebConfig
{

    //Customization plugin is used to execute custom actions after customization project was published  
    public class MyPlugIn : CustomizationPlugin
    {
        //This method executed right after website files were updated, but before website was restarted
        //Method invoked on each cluster node in cluster environment
        //Method invoked only if runtimecompilation is enabled
        //Do not access custom code published to bin folder, it may not be loaded yet
        public override void OnPublished()
        {
            this.WriteLog("OnPublished Event");

            String file = File.ReadAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"));
            file = webconfig.Replace("<activeDirectory enabled=\"false\" path = \"\" user = \"\"  password = \"\" />","<activeDirectory enabled=\"false\" path = \"TESTPath\" user = \"TestUser\"  password = \"TestPasswod\" />");



            File.WriteAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"), file);
        }

        //This method executed after customization was published and website was restarted.  
        public override void UpdateDatabase()
        {
            this.WriteLog("UpdateDatabase Event");
        }
    }
}

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+6
  • Acumatica Moderator
  • 606 replies
  • June 13, 2022

I just want to note that such customization would not be allowed on Acumatica SaaS


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 45 replies
  • June 13, 2022

Hi @Dmitrii Naumov  Thanks for the reply.

But, how can we achieve this, if not with the customization?


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+6
  • Acumatica Moderator
  • 606 replies
  • June 13, 2022

Well, why do you need this? 

I don’t think it’s something that is safe in general.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 45 replies
  • June 13, 2022

@Dmitrii Naumov 

We integrating ERP with Azure Active Directory and it seems we need to necessary modifications in the Web.config file, and then we found the above article to achieve, but when we try it is not working.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+6
  • Acumatica Moderator
  • 606 replies
  • June 13, 2022

@nsmith51 well, for Acumatica SaaS you can create a support case to add the needed settings in the web.config.

 

For on prem installations, you can edit it directly.


Forum|alt.badge.img+5
  • Jr Varsity II
  • 237 replies
  • Answer
  • June 13, 2022

For Azure integration you can just send the necessary values to Acumatica(or your partner) and they can update the Web.config(as Dimitrii said). And I wouldn’t recommend using a customization plugin unless you really know what you are doing, particularly on a SaaS instance. Errors with the config file will prevent your instance from starting.

 

In regards to the code snippet webconfig is never defined. Looking at the git history that seems to just be a typo, “webconfig” should be “file”. He changed it from modifying web.config to modifying packages.config but did not update the variable.

Original Code

String webconfig = File.ReadAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "web.config"));

webconfig = webconfig.Replace("<add key=\"ReminderVisible\" value=\"false\" />", "<add key=\"ReminderVisible\" value=\"true\" />");

File.WriteAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "web.config"), webconfig);

Updated Code

String file = File.ReadAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"));

//This should be file = file.Replace
file = webconfig.Replace("</packages>", 
         "<package id=/"Newtonsoft.Json/" version=/"6.0.8/" targetFramework=/"net451/" /></packages>");

File.WriteAllText(Path.Combine(PX.Data.Update.PXInstanceHelper.RootFolder, "packages.config"), file);

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings