Thursday, July 14, 2011

ASP.NET C# Paths

Sooner you follow a standard practice for paths, easier it will be during the time of the application deployment and launch. The following are the common methods used in ASP.NET for paths.

Application Path: HttpContext.Current.Request.ApplicationPath;

Physical Path: HttpContext.Current.Request.MapPath(appPath), where appPath = HttpContext.Current.Request.ApplicationPath; or "~"

For physical path, you can also use, Server.Mappath("~") or Server.Mappath(appPath);

MapPath method of the Server or Request maps the specified relative or virtual path to the corresponding physical directory on the server. "~" relates to the application root or application path.

Complete URL Path: HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath;

The complete url path can be very useful if you are sending links in an email through your application for features like invitations.

Cheers!


'Love is not an emotion. It is our very existence.' - Sri Sri

No comments:

Post a Comment