The database starts speaking

I’ve made only a little progress on the API side with connecting to a database and selecting advertisements by a category. It works (tested by Postman only), but there is a shame in code for now because I struggled with making projection work for a while or two. The MongoDB driver seems to be unable to convert documents to C# objects which have less properties. I don’t want to get content of advertisements when they are displayed on a list, so I’ve created a limited view model – but its properties must be initialized one by one explicitly, no automation here.

Since I’ve established a connection between the API and a database and the Internet says that revealing database credentials in public is a big no-no, I’ve checked a solution offered for ASP.NET Web.config files. It is provided by .NET Framework and is called aspnet_regiis. Its features include some CRUD operations on ASP.NET installation, but there are also some referring to en- and decryption of configuration files. Just point to a config file and its subelement and that subelement will get encrypted. For example, my command was

aspnet_regiis -pef "connectionStrings" "<my_repository_absolute_path>\Addregator\API\Addregator.API"

where -pef means encryption (Please, Encrypt File?), as opposed to -pdf used for decryption. That’s it. The trick is that decryption will break on another computer due to a missing key (otherwise anyone could obviously download a GitHub project and decrypt the config with their aspnet_regiis). In that case there is some more magic necessary for sharing that key, but I don’t need it and can’t check it, so I can only redirect to the command line help and some documentation. What is important is the fact that encrypting the config doesn’t affect an application at all – as the above documentation says:

ASP.NET will automatically decrypt encrypted configuration elements when the Web.config file is processed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s