Knowing ASP.Net Application server side path

There are a lot of questions that once you answered them they look like really simple, some even stupid. This post is about the answer of one of this kind of questions.

How to know the application path in server side of an ASP.Net page?

One of many ways is to use the MapPath method of the Page class:

this.MapPath("~");

The use of “~” is new in ASP.Net 2.0 and represents the root path for an application.

Usually you don’t need to know the server side application path, but suppose you have the page deployment in a hosting environment and you need to access a writing permission directory outside of the application path or any other URI Web visible.

Differences in paths within a development and production environments

If you know the server directory structure, you can simulate it in your development system, usually in a virtual directory in IIS, but your application must be deployed in the domain name root.

In your development server you have one directory structure for you application and your server and in the production server you have another one. So, you need to know the server side path of you application in order to locate correctly the writing permission directory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s