线程调用方法 System.Web.HttpContext.Current.Server.MapPath()
2012-11-07 13:49
489 查看
在多线程里面使用HttpContext.Current,HttpContext.Current是得到null的.
所以在线程调用方法,方法中类里面的System.Web.HttpContext.Current.Server.MapPath() 获取不到对象。
应该这么用:
所以在线程调用方法,方法中类里面的System.Web.HttpContext.Current.Server.MapPath() 获取不到对象。
应该这么用:
public static string MapPath(string strPath) { if (HttpContext.Current != null) { return HttpContext.Current.Server.MapPath(strPath); } 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); } }
相关文章推荐
- System.Web.HttpContext.Current.Server.MapPath("~/upload/SH") 未将对象引用设置为实例对象
- 线程Thread调用时System.Web.HttpContext.Current为NULL
- System.Web.HttpContext.Current.Server.MapPath()
- asp.net后台导出excel的方法:使用System.Web.HttpContext.Current.Response导出excel
- System.Web.HttpContext.Server.MapPath()
- System.Web.HttpContext.Current.Session为NULL解决方法
- C# webservice HttpContext.Current.Response.End() 引发线程中断的处理
- 文件上传 content-type:application/json System.Web.HttpContext.Current.Request.InputStream 读取不到数据
- System.Web.HttpContext.Current是什么
- System.Web.HttpContext.Current.Session获取值出错
- System.Web.HttpContext.Current.Session为NULL值的问题?
- System.Web.HttpContext.Current vs. ControllerContext.HttpContext (almost the same)
- System.Web.HttpContext.Current.Cache与System.Web.HttpRuntime.Cache指向同一个引用
- string s = HttpContext.Current.Server.MapPath("");
- System.Web.HttpContext.Current.Session为NULL值的问题?
- 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录
- System.Web.HttpContext.Current.Session为NULL值的问题?
- System.Web.HttpContext.Current.Session获取值出错
- HttpContext为null new HttpContextWrapper(System.Web.HttpContext.Current)
- WebServcies 调用方法异常:System.Web.HttpRequestValidationException: 从客户端中检测到有潜在危险的 Request.Form 值。