Applying Open Graph or “How to share pretty info?”

After working on a new website yesterday I was ready to share my progress with some friends and I was dismayed that the link produced on Facebook was not pretty, the way other site are automatically linked with a nice picture and the right kind of info. Not to be discouraged I figured I had to do better…

The Open Graph Protocol

A little searching led to the Open Graph protocol: “The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.”

So in other words: the regular meta tags I was using were not helping I needed to add ogp.me tags.

There is some help on page, but a basic example for your homepage is not on the OGP.ME webpage so I figured I’d share my result:

    <meta property="og:title" content="Chianso: digitaal kindvolgsysteem, documentbeheer en kinddossier." />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="https://www.chianso.nl/" />
    <meta property="og:image" content="https://www.chianso.nl/Images/ChiansoLogoShareX256.jpg" />
    <meta property="og:site_name" content="Chianso" />
    <meta property="og:description" content="Chianso biedt een digitaal kindvolgsysteem, online documentbeheer en digitaal kinddossier waarmee voldaan wordt aan nieuwe IKK regelgeving, kwaliteitsverbetering op de groep en kostenbesparing door het terugbrengen van administratieve handelingen." />
    <meta property="og:locale" content="nl_NL" />

 

Now what I found is that the image you want to share cannot be larger than 8MB, also, even though I found no documentation for this, JPG images seem to work better than PNG.

Facebook debugger

So one way of getting this right is adding the info to your website and the trying to share a link on Facebook. This will work once… then the next try may not show any of your changes. A very useful tool at this point is the Facebook Debugger. It will load all the metadata from your site and provide a link preview. Together with a bunch of hints and useful info AND it offers a ‘Scrape Again’ button, which invalidates the caching that is in play.

You can find the debugger here:  https://developers.facebook.com/tools/debug/sharing

Result

Facebook-ChiansoLink

Yeah!

Reinstall NuGet packages after targeting newer .NET Framework

I recently upgraded all projects in a solution to .NET 4.7 and started seeing some NuGet warnings:

target net

Essentially what seems to happen is that the NuGet package was installed when .NET 4.6 was the runtime target and this package may or may not need to be reinstalled (everything was functioning, but I just don’t like warnings when compiling).

Turns out there is no UI button for reinstalling a package, so the Package Manager Console is the place to go. The following command will reinstall the appropriate package for all project that use the package:

Update-Package -Id <package_name> –reinstall

Note that as soon as you’ve typed -Id you can use <Tab> to get a drop down list of installed packages.

For more variations of the command see: https://docs.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages

Tracking active document in Visual Studio 2017

I used to have active work item tracking turned on in my Solution Explorer, but that can get annoying, so I turned it off, but then I found I spend too much time searching for my active document. I figured there must be an easier way. Sure enough, Visual Studio has got me covered on this…

So, active item tracking is set in the configuration settings:

ActiveItem1

As you see, I have turned it off.

Now when you have an active document open in the editor, the Solution Explorer will start a bi-directional arrow icon:

ActiveItem2

Press it to have the solution explorer track down the active document in the solution explorer. The feature is called ‘Sync with Active Document’. Also accesible via keyboard shortcut: CTRL+[, S

 

 

Database-Update to recreate database on Azure

I’ve been working on an Entity Framework Code First solution using an Azure database. The migrations work like a charm, but often I’d like to recreate the database from scratch and re-seed from scratch. DropAndRecreate does not work due to permission issues, so the next best thing is to drop all tables in the database and use Database-Update from the Package Manager Console to recreate the database.

I use the following scripts to drop every constraint and then every table:


while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY' and CONSTRAINT_SCHEMA != 'sys'))
begin
declare @sql nvarchar(2000)
SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
exec (@sql)
PRINT @sql
end


while(exists(select 1 from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA != 'sys'))
begin
declare @sql nvarchar(2000)
SELECT TOP 1 @sql=('DROP TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + ']')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA != 'sys'
exec (@sql)
PRINT @sql
end

After which I use the Package Command Console to run:


Update-Database -ConnectionStringName AzureDevTest

Since the migration history table is missing it will run all the migrations.

Reset password via RDP session

The feature is ancient and you would think I would always remember, but just as a reminder to myself and to help those that don’t know:

When you’re logged into a remote machine using a remote desktop session and you want to change your password on the remote machine, use CTRL-ALT-END to see the change password option ( so END instead of DEL ).

rdp-password

Get the day of the week, in the right language

I’m working on an app that at some point will need to work in multiple languages and needed to display the day of the week to the user. I started with:

string label = DateTime.Today.DayOfWeek.ToString()

But that give me the name of the enumeration, which is of course in English. In order to get the name based on the current language setting I needed the following code:


var culture = System.Globalization.CultureInfo.CurrentCulture;
string label = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);

Happy coding!