I have issue with configuring web.config in .Net Core 2.0. it’s not work.
I think maybe .Net Core 2.0 use appsetting.json instead of web.config
I have tried to add web.config to my project and use this code for register database connection
var dbFactory = new OrmLiteConnectionFactory(
And error is
ArgumentNullException: ConnectionString must be setParameter name: ConnectionString
You can still use appSettings in Web.config for your App config which is the default AppSettings provider, but you should be using the AppSettings API to read from Web.config or any other AppSettings source, e.g:
var connString = AppSettings.GetString("agency_dev");
then you can use their GetConnectionString helper method to get the connection string as @hoaihuongbk demonstrated above. As I understand it, calling AppSettings.GetString as you suggested would only return that key/value if it was on the top level of the config file (e.g. it maps to the index accessor on IConfiguration), but not nested under a ConnectionStrings category. Is my understanding correct? If so, what is the suggested way to get the connection string from the AppSettings in a .NET Core app?
I’d imagine like binding any other custom Poco as neither .NET Core’s IConfiguration API or ServiceStack’s IAppSetting has any knowledge or special APIs for retrieving connection string configurations. I’d personally just store it like any other string, there’s no reason it needs to be a special object that’s treated differently.