线程Thread调用时System.Web.HttpContext.Current为NULL的问题

yellowtree12 2011-11-04 05:16:06
我想调用System.Web.HttpContext.Current.Server.MapPath("strMath"),可是提示错误,系统找不到该文件,如果我的文件是放在C:\windosw下,那这段代码该怎样写System.Web.HttpContext.Current.Server.MapPath("strMath"),注意是线程Thread调用。
...全文
312 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xysxjf 2011-12-02
  • 打赏
  • 举报
回复
自定义一个方法
public static string MapPath(string strPath)
{
if (System.Web.HttpContext.Current != null)
{
return System.Web.HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "");
strPath = strPath.Replace("~", "");
if (strPath.StartsWith("\\"))
{
strPath = strPath.TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
wsxqaz 2011-11-04
  • 打赏
  • 举报
回复
Environment.CurrentDirectory
krenyelang 2011-11-04
  • 打赏
  • 举报
回复
string strpath=@"C:\windosw";
yellowtree12 2011-11-04
  • 打赏
  • 举报
回复
我是在cs里面写这个,怎样在cs里面使用这个获取应用程序根目录的路径?
leoboss1 2011-11-04
  • 打赏
  • 举报
回复
我也不会
wsxqaz 2011-11-04
  • 打赏
  • 举报
回复
你是在asp.net程序里调用了这个么?

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧