torsdag, september 15, 2011

Quick Tip: Accessing MapPath method When HttpContext.Current is null

If you ever tried to use the HttpContext.Current.Server.MapPath method from a thread or within a Sitecore EventHandler, you will notice, that the HttpContext.Current is null.

How do you get the absolute path of a file when you only know the relative path? Well, you can’t use HttpContext.Current.Server but you can use the alternative:

HostingEnvironment.MapPath("~/App_Config/MailTalkServices.config");
Located in the namespace: 
System.Web.Hosting;

Ingen kommentarer: