做项目的时候,System.Web.HttpContext.Current.Server.MapPath("~/upload/SH")   获取路径本来这个方法用的好好的

因为需要实时的输出日志,我就使用了多线程,System.Web.HttpContext.Current.Server.MapPath()    他就报  未将对象引用设置为实例对象

在网上 找到 别人写的下面的方法 挺好用的

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);
}
}

System.Web.HttpContext.Current.Server.MapPath("~/upload/SH") 未将对象引用设置为实例对象的更多相关文章

  1. HttpContext.Current.Server.MapPath("") 未将对象设置到引用的

    在多线程中使用该方法获取目录报错:未将对象设置到引用 #region 上传图片到腾讯 public async Task<Result> UploadImageToWX(string ba ...

  2. 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录

    ASP.NET提供了静态属性System.Web.HttpContext.Current,因此获取HttpContext对象就非常方便了.也正是因为这个原因,所以我们经常能见到直接访问System.W ...

  3. HttpContext.Current.Server.MapPath("/") 未将对象设置到对象的实例异常。

    多线程中的System.Web.HttpContext.Current.Server.MapPath("/") 多线程中Server.MapPath会失效... 网上找到几种解决方 ...

  4. System.Web.HttpContext.Current.Session为NULL解决方法

    http://www.cnblogs.com/tianguook/archive/2010/09/27/1836988.html 自定义 HTTP 处理程序,从IHttpHandler继承,在写Sys ...

  5. HttpContext为null new HttpContextWrapper(System.Web.HttpContext.Current)

    HttpContext = (context == null ? new HttpContextWrapper(System.Web.HttpContext.Current) : context);

  6. System.Web.HttpContext.Current.Session获取值出错

    在自定义类库CS文件里使用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 一般情况下通过这种方式获取Sessi ...

  7. string s = HttpContext.Current.Server.MapPath("");

    string s = HttpContext.Current.Server.MapPath(""); 获取当前文件夹路径 而后用相对路径读取图片

  8. System.Web.HttpContext.Current.Session为NULL值的问题?

    自定义 HTTP 处理程序,从IHttpHandler继承,在写System.Web.HttpContext.Current.Session["Value"]的时 候,没有问题,但 ...

  9. .NET System.Web.HttpContext.Current.Request报索引超出数组界限。

    移动端使用Dio发送 FormData, 请求类型 multipart/form-data, FormData内可以一个或多个包含文件时. 请求接口时获取上传的fomdata数据使用 System.W ...

随机推荐

  1. zepto源码--width,height--学习笔记

    width和height函数,实际上通过css方法也完全可以取到这两个函数的结果.获取width,$elem.css('width');设置width的话,$elem.css('width', 100 ...

  2. EF6 CodeFirst 启用Migration,常用命令

    Enable-Migrations –EnableAutomaticMigrationsAdd-Migration [MigrationName] [-Force]Update-Database –T ...

  3. C#5.0 .net 4.5示例

    //filename: MathOperations.cs using System; using System.Collections.Generic; using System.Linq; usi ...

  4. angularJs的工具方法

  5. 我的工具箱之FileZilla_3.11.0.1_win32-setup.1432524055

    FileZilla是用于在Win和Linux之间传递文件的工具,支持FTP和SFTP. 下载地址:http://pan.baidu.com/s/1gelyIYn 2016年3月2日10:29:30

  6. 文明3地图之二-大n型地图

    存档文件:http://files.cnblogs.com/files/xiandedanteng/civ3bigN20160214.rar 地图: 简介: 这份地图几乎没有岛屿,整块大陆都连在一起像 ...

  7. http://blog.sina.com.cn/s/blog_6940cab30101hn9j.html

    http://blog.sina.com.cn/s/blog_6940cab30101hn9j.html

  8. iOS工程如何支持64-bit

    苹果在2014年10月20号发布了一条消息:从明年的二月一号开始,提交到App Store的应用必须支持64-bit.详细消息地址为:https://developer.apple.com/news/ ...

  9. LeetCode Shortest Word Distance III

    原题链接在这里:https://leetcode.com/problems/shortest-word-distance-iii/ 题目: This is a follow up of Shortes ...

  10. Spring Boot flyway的启动时机比较早

    flyway,如果已经创建的版本V1中已经更新,则会validation报错 at org.springframework.boot.devtools.restart.RestartLauncher. ...