原因:20150703 解释下为什么当前请求上下文会为null,因为多线程情况下,当前线程可能并非http请求处理线程,根本没发生请求,所以无法获取到HttpContext就是null. public static string MapPath(string strPath) { if (HttpContext.Current != null) { return HttpContext.Current.Server.MapPath(strPath);//有http请求 } else //非web程序引用 { strPath = strPath.Replace("/", “\”); if (strPath.StartsWith("\")) { //strPath = strPath.Substring(strPath.IndexOf(’\’, 1)).TrimStart(’\’); strPath = strPath.TrimStart(’\’); } return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); } }