Request.AplicattionPath drop server name

Hi All,
I used Request.ApplicationPath for referencing my documents upload directory . It worked great in my dev environment. However, when I copied the project to my production server, the reference is completely removing the server name.However, on production, the document reference is set to http://upload/mydoc.doc
You can see that it is dropping the server name completely.
5/4/2009 10:00:18 PM
📃 93655 articles.

💬 1 Replies

If you read the definition of Request.ApplicationPath, it says "Use this property to construct a URL relative to the application root from a page or Web user control that is not in the root directory. This allows pages and shared controls that exist at different levels of a directory structure to use the same code to link to resources at fixed locations in the application."
Here's a much more reliable way to obtain full qualified http URL:   
string fullApplicationPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath + "/"; // using UriPartial.Authorith handles correct http scheme, i.e.: 'http' and 'https'

Jack Yang
.NET Developer
5/4/2009 11:16:40 PM