Access web.config values from client customization

I think UD tables would be the more “correct” solution anyway.

1 Like

I don’t think I’d put variable like that in the web.config. I’d put those in a UD table like @Evan_Purdy said. Putting them in the web.config could be messy come upgrade time.

1 Like

Interesting… from article links below, I got the feeling it could be read via .Net clients but …didn’t do any actually testing/verification.

Let us know if you get a working example?

1 Like

Thanks for the ideas. I will post the code if I can figure out a working solution.

Just an FYI…
Screwed around with some code below for a few minutes…

  • only returned a blank AND throws a warning when testing code
    But…gave me some ideas, unfortunately, no time to explore.

using System.Configuration;

private void btnReadAppSettings_Click(object sender, System.EventArgs args)
{
	try
    {
    string sFrameLimit = ConfigurationSettings.AppSettings.Get("FrameLimit");
	MessageBox.Show("sFrameLimit: " + sFrameLimit);
    }
	catch (Exception e)
    {
    	MessageBox.Show("Error: " + e);
    }

}
1 Like

Even better than a UD table, is User Codes. See

3 Likes

Ah yea, user codes. I forgot about those. That would be better than a UD table and better than the web.config IMO.

1 Like

User codes, agreed.

1 Like

Thanks everyone for the ideas. A UDCode will probably work in this case. However, I am still left wondering if there is a way to access the web.config or even the client.sysconfig from a client customization

Depends on how “universal” you want it to be. Could you accept hardcoding the path to that file?

Or do you want it to be all automatic, such that it would be totally independent of the App name, or where it is stored?

If a static path is okay, just use the following in a BPM Exec Custom Code widget

webConfigText = System.IO.File.ReadAllText(@"c:\inetpub\wwwroot\UAT_102300\Server\web.config");

That assigns the contents of the file web.config, to the variable webConfigText.

My goal is to make it as universal as possible so the client code is portable. My preference is to store it uniquely on the application server and the client would not contain any file pathing. In my mind, this should simplify changing
servers / upgrades, etc

If you can programatically read the “server” value displayed in the status bar:

image

You could get closer to being universal, if you assume that the APP is deployed to
`“C:\inetpub\wwwroot” by using:

string srvapp = "usdcaaps00371/UAT_102300";
string srv = srvapp.Split('/')[0];
string app = srvapp.Split('/')[1];

string pth = @"\\"+srv+@"\c$\inetpub\wwwroot\"+app+@"\server\web.config";

webConfigText = System.IO.File.ReadAllText(pth);

And if you were really ambitious, you could use functions like Directory.GetLogicalDrives(), Directory.GetDirectories(), etc… to search and find the web.config file.

Just need to figure out how to get srvapp

You can get the server or app like this:

using Microsoft.Web.Administration;
using System.Web.Hosting;

reference assemblies:
Microsoft.Web.Administration
System.Web - EXTERNAL

ServerManager mgr = new ServerManager();
string SiteName = HostingEnvironment.ApplicationHost.GetSiteName();
Site currentSite = mgr.Sites[SiteName];

string ApplicationAlias = HostingEnvironment.ApplicationVirtualPath;
string ApplicationName = ApplicationAlias.Substring(1);
Application app = currentSite.Applications[ApplicationAlias];

string currApp = app.ApplicationPoolName.ToString();

string prefix = "-";
parsedEnvironment = currApp.Substring(currApp.IndexOf(prefix) + prefix.Length).ToUpper();

Change prefix or whatever suits your server/app name

1 Like

Thanks for the information! I can locate System.Web.dll in the .NET 4.0 folder (C:\Windows\Microsoft.NET\Framework64\v4.0.30319). I assume I copy this DLL into the client folder to allow the reference to take place (or update xml for assembly reference)…
Two questions-

  1. Do I need to add this DLL to all client PCs
  2. Where is Microsoft.Web.Administration.dll?

My bad,

That was for server side BPMs. Here is the client side code:

Ice.Core.Session currentSession = (Ice.Core.Session)oTrans.Session;
string erpEnvironment = currentSession.AppServer.ToString();

You may need to play around with parsing out the string depending on your server name

1 Like

My 2 cents - never ever give the client access to server files! If UDCodes isnt acceptable, might I suggest either a dedicated DB or shared folder with security.

1 Like

Yes that makes sense. I was just hoping that if contents of one of the .config files were already stored in memory or accessible via adapters that I could utilize them. I will be storing credentials to an external site and was hoping to make them relatively easy to update if they change and difficult to access for users who gain access to our database/interface without making things overly complicated.

Thanks!

Just to be clear, when you say “client”, are you referring to code for your specific client (aka your customer), or the client program that runs on a users workstation?

I am referring to client program that runs on a user’s workstation.