Asp.Net - Web.Config - PhysicalApplicationPath

  • Thread starter Thread starter Shock
  • Start date Start date
S

Shock

I am interesting in figuring out how to use the PhysicalApplicationPath method or another equivalent method inside of the Web.Config file. I have a key in my appsettings that looks something like this
<add key="key" value="D:\App\dir\dir" />

Basically I want to be able to use the method to find the path that the web app is sitting in. Which is

D:\App\dir\dir

that way I could define my key as

<add key = "key" value = path />

This seems trivial, but I am not familiar with the intricacies of the web.config file.

To be able to do this would allow users to install the app in different locations and still be able to access the directories under the applications path.

Thanks ahead,

Shocks
 
If I understand you correctly, you want to have other settings in your web.config file which use the path setting that you have set? So these settings need to point to some path or file, and you want to make this work regardless of where the app is installed?

Would you not just be able to use relative paths? In the code behind, when you access these relative paths from web.config, you could always apply the Physical application path to them if necessary. Or you could use URLs, using the '~' syntax to indicate they come from the applications root directory. In codebehind, you can use ResolveURL to convert this to a proper URL, and then convert the URL to the physical path (using Server.MapPath).

I'm not sure if thats what you want to be able to do, as I'm not sure what you mean in your last sentence "To be able to do this would allow users to install the app in different locations and still be able to access the directories under the applications path.". When you say users, do you mean end-users of the app, or developers who are installing the webapp?

Cheers,
Pete Beech

I am interesting in figuring out how to use the PhysicalApplicationPath method or another equivalent method inside of the Web.Config file. I have a key in my appsettings that looks something like this
<add key="key" value="D:\App\dir\dir" />

Basically I want to be able to use the method to find the path that the web app is sitting in. Which is

D:\App\dir\dir

that way I could define my key as

<add key = "key" value = path />

This seems trivial, but I am not familiar with the intricacies of the web.config file.

To be able to do this would allow users to install the app in different locations and still be able to access the directories under the applications path.

Thanks ahead,

Shocks
 
Back
Top