Solved

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

  • 11 June 2022
  • 8 replies
  • 508 views

Userlevel 3
Badge

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?

 

 

icon

Best answer by markusray17 13 June 2022, 20:22

View original

8 replies

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.

Userlevel 3
Badge

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

 

Userlevel 7
Badge +5

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

Userlevel 3
Badge

Hi @Dmitrii Naumov  Thanks for the reply.

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

Userlevel 7
Badge +5

Well, why do you need this? 

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

Userlevel 3
Badge

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

Userlevel 7
Badge +5

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

Userlevel 6
Badge +5

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved