Skip to content

Instantly share code, notes, and snippets.

@mahizsas
Forked from huanlin/ASP.NET URL and Path.txt
Last active August 29, 2015 14:18
Show Gist options
  • Save mahizsas/e1f26bae2c259d6803a7 to your computer and use it in GitHub Desktop.
Save mahizsas/e1f26bae2c259d6803a7 to your computer and use it in GitHub Desktop.
Related Properties
- HttpRuntime.AppDomainAppVirtualPath
- Request.ApplicationPath
Methods for getting physical file path:
- System.Web.HttpContext.Current.Server.MapPath()
Methods for generating content URL:
- System.Web.UI.Control.ResolveUrl() or Page.ResolveUrl()
- System.Web.Mvc.UrlHelper.GenerateContentUrl()
- System.Web.VirtualPathUtility.ToAbsolute()
Example of UrlHelper.GenerateContentUrl:
var context = new HttpContextWrapper(HttpContext.Current);
string url = UrlHelper.GenerateContentUrl("~/Images/photo.jpg, context);
References
- ResolveUrl in ASP.NET - The Perfect Solution
http://www.codeproject.com/Articles/53460/ResolveUrl-in-ASP-NET-The-Perfect-Solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment