Skip to main content

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?

 

 

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.


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");
}
}
}

 


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


Hi @Dmitrii Naumov  Thanks for the reply.

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


Well, why do you need this? 

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


@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.


@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.


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