Paths

brawney

Perch
When they started moving people to win5 several people had problems because they were using hard coded paths in their apps (c:\hshome and on the new server it was d:\hshome). I have ASP.NET apps and have paths defined in my web.config files. What is the best way to avoid this problem?
 
brawney said:
When they started moving people to win5 several people had problems because they were using hard coded paths in their apps (c:\hshome and on the new server it was d:\hshome). I have ASP.NET apps and have paths defined in my web.config files. What is the best way to avoid this problem?

SubSpace is correct; use relative paths.

Like you, brawney, I have paths defined in my web.config file. For most things, simply combining the appropriate appSetting with name of the desired file does the trick; for example, ImagePath & "image.jpg", where ImagePath was retrieved from an appSetting whose value might be "images/".

This works fine for dynamically generating html of for use in custom web controls, but for things like a connection string to an Access database, you must find a way to provide a physical path for your connection string. You can do this using PhysicalDbPath = Server.MapPath(RelativeDbPath) to convert the relative path to the physical path. So you can still define your relative path in the web.config file (such as "data/mydb.mdb") and make it work.

Hope that helps...

riley
 
For some function calls like Page.LoadControl you can use "~" to refer to the root of your application. e.g.

Code:
UserControl myUC = (UserControl)LoadControl("~/uctest.ascx");

If uctest.ascx is located, for example at:

D:\inetpub\wwwroot\myapp\uctest.ascx

That sentence will work fine if "D:\inetpub\wwwroot\myapp\" is the root of your application.

You can use the same trick for page directives:

Code:
<%@ Register TagPrefix="uc1" TagName="mytagname" Src="~/uctest.ascx" %>

This character only works in ASP.NET as far as I know
 
Back
Top