What is the best practice to publish an ASP.NET website?

pisceswzh2010
pisceswzh2010 used Ask the Experts™
on
Dear all,

Is there any best practice to publish an ASP.NET website in general?  

To be more specific, I have developed a website that requires to retrieve some data on the server hard driver, so in the development environment, I created folder to simulate the environment.  However the absolute paths of that folder (on the server and on my development machine) are different.  This means whenever I want to publish, I need to modify the value of that path.  What makes it worse is that that value has been used in multiple places in the project, so I have to change every of them.  This is very tedious.

Is there any better solution for this specific problem?  And is there any best practice to publish an ASP.NET website?  Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Carl TawnSenior Systems and Integration Developer

Commented:
Well one best practice is not to hard-code paths into your code :)  If you can, move them out to the config file, or even use virtual directories to map to the physical folder (unless you specifically need to files to be non-web browsable)

Author

Commented:
Well, I know what you mean, but I did encounter some issue trying to use relative path.  The files I'm trying to access are in sub-folders under my application folder and these files are in txt format.  The application needs to retrieve the text in those txt files.  I, therefore, use the StreamReader with the following code.

Also how should I use the config file?  Are you talking about the web.config file?  Thanks.

string txtReturn;
using (StreamReader sr = new StreamReader(strAppPhyPath + @"dialog\Facts\UploadFile.txt"))
{
    txtReturn = sr.ReadToEnd();
}
return txtReturn;

Open in new window

Senior Systems and Integration Developer
Commented:
Yes, I was referring to web.config.

If the paths are relative then you can use Server.MapPath to translate a relative path into a physical path:


string txtReturn = string.Empty;

string filepath = Server.MapPath("~/dialog/facts/UploadFile.txt");
using (StreamReader sr = new StreamReader(filepath))
{
    txtReturn = sr.ReadToEnd();
}

return txtReturn;

Open in new window

Author

Commented:
Thanks.  I forgot to use "Server.MapPath".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial