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;

 

posted @ 2018-07-05 17:45  enych  阅读(809)  评论(0编辑  收藏  举报