Skip to content

Instantly share code, notes, and snippets.

@tonysneed
Last active November 10, 2019 11:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysneed/e437e698164cd9e41176 to your computer and use it in GitHub Desktop.
Save tonysneed/e437e698164cd9e41176 to your computer and use it in GitHub Desktop.
ASPNetCore: App_Data with LocalDb File
{
"Data": {
"SampleDb": {
"ConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\SampleDb.mdf;Integrated Security=True; MultipleActiveResultSets=True"
}
}
}
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Set up configuration sources ...
// Set up data directory
string appRoot = appEnv.ApplicationBasePath;
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(appRoot, "App_Data"));
}
@tonysneed
Copy link
Author

@tonysneed
Copy link
Author

@tonysneed
Copy link
Author

Updated Startup to use IApplicationEnvironment ctor parameter instead of static methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment