diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 57ac262197..5a28290126 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -15,6 +15,8 @@ using MusicStore.Models; using MusicStore.Web.Models; using System; using System.Collections.Generic; +using System.IO; +using System.Reflection; public class Startup { @@ -52,8 +54,8 @@ public class Startup { var configuration = new Configuration(); configuration.AddEnvironmentVariables(); //If configuration flows through environment we should pick that first - configuration.AddJsonFile("Config.json"); - + configuration.AddJsonFile(Path.Combine(GetApplicationBasePath(), "Config.json")); + string _username = configuration.Get("DefaultAdminUsername"); string _password = configuration.Get("DefaultAdminPassword"); string _role = "Administrator"; @@ -76,4 +78,28 @@ public class Startup await userManager.AddToRoleAsync(user, _role); } } + + //To find the application base path at runtime. + private static string GetApplicationBasePath() + { +#if NET45 + var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; +#else // CORECLR_TODO: ApplicationBase + var appDomainType = typeof(object) + .GetTypeInfo() + .Assembly + .GetType("System.AppDomain"); + + var currentAppDomainProperty = appDomainType.GetRuntimeProperty("CurrentDomain"); + + var currentAppDomain = currentAppDomainProperty.GetValue(null); + + var getDataMethod = appDomainType + .GetRuntimeMethod("GetData", new[] { typeof(string) }); + + string applicationBase = (string)getDataMethod.Invoke(currentAppDomain, new object[] { "APPBASE" }); +#endif + + return applicationBase; + } } \ No newline at end of file diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index 754b2a437a..5bff92db79 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -50,7 +50,10 @@ "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.Diagnostics.Tools": "4.0.0.0", - "Microsoft.ComponentModel.DataAnnotations": "4.0.10.0" + "Microsoft.ComponentModel.DataAnnotations": "4.0.10.0", + "System.Reflection": "4.0.10.0", + "System.Reflection.Extensions": "4.0.0.0", + "System.IO": "4.0.0.0" } } }