Friday, December 31, 2010

.NET Utility class for getting application name of a site

 

In our application we needed to find out application name of a site for routing. One solution for finding out application name from URL using regular expression. but VirtualPathUtility class of .NET make it easy to get application name by using relative path. VirtualPathUtility class provides utlity methos for common operations involving virtual paths. We do not know with which name our application would be deployed. so for constructing URL we use ‘~’ for relative path. So VirtualPathUtility.ToAbsolute(“~”) give me the absolute path ‘/Website’ were my website URL is http://localhost/Website. Also for getting relative path of a resource from a user control of a site you can use VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/jquery-1.4.1.js");

No comments:

Post a Comment