C# 获得根路径
asp.net:
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/tmp/");
winform:
System.AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\tmp\\";
AppDomain.CurrentDomain.RelativeSearchPath
if (HttpContext.Current == null) { serverLogPath = AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\tmp\\"; } else { serverLogPath = HttpContext.Current.Server.MapPath("~/App_Data/tmp/"); }
GarsonZhang www.yesdotnet.com
获取当前运行程序
windows app的执行路径AppDomain.CurrentDomain.BaseDirectory
asp.net的执行路径AppDomain.CurrentDomain.SetupInformation.PrivateBinPath或者AppDomain.CurrentDomain.RelativeSearchPath
后者获取回来是带有“bin”文件夹在后面的
ASP.NET MVC测试
C# 全选
System.Environment.CurrentDirectory // E:\\GZ\\GZBlog\\YESCMS
System.AppDomain.CurrentDomain.BaseDirectory // E:\GZ\GZBlog\YESCMS\bin\Debug\net5.0\
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase // E:\GZ\GZBlog\YESCMS\bin\Debug\net5.0\
AppDomain.CurrentDomain.RelativeSearchPath // null
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post YES开发框架