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

How to patch new properties in web.config

Vote:
 

Hi Guys,

I have a requirement of patching some properties to the existing web.config. I am trying to do it via Add-on so i dont have access to web.config but i want to make my property added to the web.config of the user who uses my Add-on.

Example : 

For the below section in the web.config i want to add the language1 from a external config file which comes as part of add-on.

<profile defaultProvider="DefaultProfileProvider">
<properties>
<add name="Address" type="System.String" />
<add name="ZipCode" type="System.String" />
<add name="Locality" type="System.String" />
<add name="Email" type="System.String" />
<add name="FirstName" type="System.String" />
<add name="LastName" type="System.String" />
<add name="Language" type="System.String" />
<add name="Country" type="System.String" />
<add name="Company" type="System.String" />
<add name="Title" type="System.String" />
<add name="CustomExplorerTreePanel" type="System.String" />
<add name="FileManagerFavourites" type="System.Collections.Generic.List`1[System.String]" />
<add name="EditTreeSettings" type="EPiServer.Personalization.GuiSettings, EPiServer.Cms.AspNet" />
<add name="ClientToolsActivationKey" type="System.String" />
<add name="FrameworkName" type="System.String" />
<add name="Language1" type="System.String"/>
</properties>
</profile>

Do we have any thing similar like patching we can do for the same? Any specific process like transformation for environments in DXC.

Regards,

Manik

#208525
Oct 25, 2019 16:13
Vote:
 
#208540
Oct 26, 2019 6:12
Vote:
 

Hi Ravindra,

Thanks for your response.

Is there any other way by using only configs like any transform files or any specific that episerver will pick the config from another config file.

Because the change which I wanted to make should exist all the time and it is part of add-on, so I may not have the initial call with me.

Regards,

Manik

#208542
Oct 26, 2019 6:31
Vote:
 

Then you can apply it using the tranform file using the visual studio slow cheetah extension.

#208543
Oct 26, 2019 6:51
Vote:
 

As I am using it from add-on , I don't have that feasibility of updating using transforms. Because add-on once installed it will copy my dlls and config. So I won't have the access to the code base. What I am developing is a add-on and in that add-on I require changes in web.config.

Regards,

Manik

#208544
Oct 26, 2019 7:19
Vote:
 

I think you can use Episerver initialization module in your add on and then write the logic in initialization module to update the values in web.config. I haven't tried this but I think it should work.

Refer my above blog post to update the property in web.config

#208545
Edited, Oct 26, 2019 11:47
Vote:
 

Writing in web.config on runtime is simply and strongly not recommended, the reason is obvious that there will be an application to recycle all the time, think can go more complex if the site is in the cloud. Site visitors will face downtime. and will not be able to do any further action on AddOn also.

There are many ways to manage this depending on requirements, hope you would have already visitied https://world.episerver.com/documentation/developer-guides/CMS/add-ons/Developing-Add-ons/

/K

#208546
Oct 26, 2019 13:40
Vote:
 

if add-on is not deterministic - you might get into infite restart loop (app starts -> addon writes to web.config -> app restarts -> addon writes to web.config -> repeat..)

please don't touch web.config -> it's not recommneded. 

if you need modify profile for example -> I would recommend to create web.config transform file (web.config.transform) where you can add your required changes. these changes will be applied during nuget package installation. more info - https://docs.microsoft.com/en-us/nuget/create-packages/source-and-config-file-transformations

#208547
Oct 26, 2019 14:15
* 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.