Guru E. Technology

need of every business.


How to Get Virtual Path?

When we work with ASP.Net application with Visual Studio, you will note that when you run  your application it will use the folder name with the server name ie(http://localhost/Webapplicationname/) and then the file which you are executing in the address bar of your browser.
I think every developer face this issue when he try to redirect or open the complete path. He needs to put the virtual path manually or need to get the virtual URL for the application.

If you use path manually then you need to update every time whenever you are hosting to another server or url. So better solution to get the virtual path dynamically/through code. Following is the code which provide the complete virtual path of your application/website:

HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpRuntime.AppDomainAppVirtualPath;

 

Tags: , ,

Posted in ASP.Net, Developer Solutions


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>