Skip to content

Instantly share code, notes, and snippets.

@huanlin
Last active February 18, 2019 02:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huanlin/6086030 to your computer and use it in GitHub Desktop.
Save huanlin/6086030 to your computer and use it in GitHub Desktop.
ASP.NET URL and Path related methods.
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