473,287 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Web.config and environment variables. Please help!

Hi, all:
I would like to know one thing: Is it possible to access an environment
variable (like PATH) from web.config file? Something like this:
<appSettings>
<add key="name" value="%Environment{PATH}\Shared"></add>
</appSettings>

or

<add key="name" value="${PATH}\Shared"></add>
or anything else?

I think itÂīs not possible the access to system or environment variables from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!
May 12 '06 #1
6 13577
No, you would have to translate these in your code that read in the value.

Cheers,

Greg Young
MVP - C#
"otto" <ot**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hi, all:
I would like to know one thing: Is it possible to access an environment
variable (like PATH) from web.config file? Something like this:
<appSettings>
<add key="name" value="%Environment{PATH}\Shared"></add>
</appSettings>

or

<add key="name" value="${PATH}\Shared"></add>
or anything else?

I think itīs not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!

May 12 '06 #2
"otto" <ot**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I think itīs not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!

May 12 '06 #3
"otto" <ot**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I think itīs not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.


It's not possible

(Sorry for the empty post previously...)
May 12 '06 #4
No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"otto" <ot**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hi, all:
I would like to know one thing: Is it possible to access an environment
variable (like PATH) from web.config file? Something like this:
<appSettings>
<add key="name" value="%Environment{PATH}\Shared"></add>
</appSettings>

or

<add key="name" value="${PATH}\Shared"></add>
or anything else?

I think itīs not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!

May 12 '06 #5
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:Om**************@TK2MSFTNGP04.phx.gbl...
No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...


Yes of course, but what value does that add? Why not just interrogate the
environment variable when required...?
May 12 '06 #6
It helps encapsulate the logic. A lot of people would have done the
replacement each time on all of their pages. Apologies with assuming you
didn't know this...you never know what people do and don't know :)

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:Om**************@TK2MSFTNGP04.phx.gbl...
No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...


Yes of course, but what value does that add? Why not just interrogate the
environment variable when required...?

May 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: A.M-SG | last post by:
Hi, We have a class library application that needs to read some application settings from it's own app.config file. I assume that a ClassLibrary.DLL can have a app.config file, but...
13
by: John Bowman | last post by:
Hi All, I've got a simple wrapper static test method on a class to expand the environment variables on a specified string: public static string ExpandEnvironmentStr(string Str) { return...
2
by: Keith Elder | last post by:
Let's say you have a stand alone C# library project that is your datalayer. When this library compiles it will produce "My.DataLayer.dll" for example. In the project you use all the new...
10
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
This has been working perfectly for months. Since we switched from ASP.NET 1.1 to 2.0, we have constant and sporadic issues with updating our applications. Touching the web.config works about...
1
by: Shashank | last post by:
Hi all, I am a new member of this community. I am making a http request to a html file placed on a Apache server. On this page there is an embeded perl statement which requires reading ...
3
by: SevDer | last post by:
Hi All, I am recently experiencing a weird problem. I don't know what exactly is the cause of the problem but here is my scenario and symptoms. First of all here is my architecture 1. I have...
2
by: Ran Raj | last post by:
In Windows environment, I want to create/update both system and user environment variables. By default, I can access/modify the variables using Start > Control panel > System > Advanced >...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file,...
3
by: Max2006 | last post by:
Hi, In our production environment, we would like to protect our database connection string against system administrators (they are admin on the web server box) I went through this article that...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.