C# 取web应用程序运行目录
HttpRuntime.AppDomainAppPath
var fullpath = System.AppDomain.CurrentDomain.BaseDirectory + "appsettings.json"; if (File.Exists(fullpath)) { using (StreamReader streamReader = new StreamReader(fullpath, Encoding.UTF8, true)) { appsettings = streamReader.ReadToEnd(); } } var rspObj = JsonConvert.DeserializeAnonymousType(appsettings, new { AppSettings = new { ConnectString = "" }, AllowedHosts = "" }); connectString = rspObj.AppSettings.ConnectString;