Monthly Archives: November 2013

MVC 5 for Visual Studio 2012

If you are still using Visual Studio 2012 and are looking for a way to have intellisense for your views made for razor 3, if you want to add a new view and a new controller with the proper menu entries in visual studio you probably noticed that with things don't work as they should.

Simply install the following 2 components:

In case the links don't work, check the original articles where I've found all the necessary information (thanks to them):

After installing these 2 components, you'll finally be able to work on MVC5, just as you were used with MVC 4. Check these screenshots:

[caption id="attachment_257" align="alignnone" width="324"]visual-studio2012-mvc5-project-controller-add-menu When you right click on "Controllers" and select "Add" you can now select "Controller..."[/caption]

[caption id="attachment_258" align="alignnone" width="367"]visual-studio2012-mvc5-project-views-add-menu When you right click on your Views folder and then select "Add" you can now select "View..." as well as new entries (see MVC 5 View options at the bottom)[/caption]

[caption id="" align="alignnone" width="605"]visual-studio2012-mvc5-project-view-scaffolding When you add a View, you can select a Model class and a Data context class, scaffolding will work also with Entity Framework 6[/caption]


Wordpress remove thousands of spam comments

If you have a wordpress blog and are receiving thousands of spam comments, and many are not recognized as spam by akismet, you should add an extra mechanism to protect your blog and save yourself a lot of time (wasted on reviewing obvious spam). Read on.

Configure your Discussion Settings

I assume you want to allow your readers to comment... if not, then you may find this page in the Dashboard very useful: Settings > Discussion


In particular:

  • Allow people to post comments on new articles: if you do not want to receive comments at all, check this option. You can override it per post (when you write/edit a post, click at the top right on "Screen Options" > "Discussion" and see a tab appearing under your post, showing these 2 options:
    • Allow comments
    • Allow trackbacks and pingbacks on this page

  • Users must be registered and logged in to comment: this probably works only for a private blog

  • Comment must be manually approved: this is a must for me. In case a spam comment is not detected, it won't be shown to the public.

  • Comment author must have a previously approved comment: this is also a good option I activate. I want to have full control on my blog.

Actively fight spam

Wordpress comes with a plugin called Akismet. In order to use it, you must sign up for an Akismet API key, Do it! Then go in the Plugins page, click on Settings (in the Akismet tab) insert the key and activate the plugin.

Akismet, in the last months, was for many users not effective anymore. It doesn't detect many obvious spammy comments as spam. Every week I get at least 30-50 comments in chinese or arabic, full of spammy links. I don't understand why akismet doesn't detect them as spam... Well, you need to add some extra protection, like a captcha or another plugin.

How to install a WordPress plugin: Browse to your Plugins page, click on "Add new" and search for it, find it in the WordPress Plugin Directory and install it from there, with a few clicks. Else you can also install it manually by downloading it from the author's page, unzipping it and copying the contents in your WordPress installation, under /wp-content/plugins/

2 WordPress Plugins that will make your life easier

Captcha control: for my blog I'm using a plugin called FunCaptcha, it works very well and it's very easy user friendly (much better than some standard captchas, difficult to understand). The user must rotate a picture by clicking it a several times, or select something. Try the example in the author's website. You must register to the author's website and get a public and private API keys. This is very easy. This plugin is excellent: since I'm using it I receive practically 0 spam comments.

Cookie control: there is also a plugin called Cookies for comments. What the plugin does is very simple. It will add a cookie to the user's browser and check if the cookie exists when the comment is entered. If it doesn't, it may be a paranoid user who deactivated cookies, or a spammer. As the majority of users doesn't deactivate cookies, and I have no time to deal with the paranoids, I simply accept the default option provided by the plugin to automatically mark as spam all comments that didn't pass the cookie check. This plugin does exactly what I said: marks as spam the spammy comments. The problem is that you will still receive hundreds or even thousands of spams that you must manually delete by clicking the "Empty Trash" button.

Conclusion: use FunCaptcha.

Clean up thousands of comments marked as spam

I don't know how, but my little blog was spammed with more than 100'000 thousands comments (wasting more than 600 MB of hosting space...). The Empty Spam button doesn't work in this case, I guess because PHP is going out of memory. So if you find yourself in the same situation, you need to manually clean up your database comments (and meta) tables yourself. This is quite easy, just run these 2 queries (I had to save them in a txt file as my host doesn't let me save this post for security reasons). Then optimize the 2 tables.

That's it. I hope that akismet will improve the spam detection, but it seems to me that extra measures have to be taken. Spammers get smarter (or the tools they use get smarter...) and we have to update our countermeasures to protect our blogs and the internet...

Run SQL script via command line

When a SQL file is too big to copy/paste it in your SQL Management Studio (getting a timeout error or such), you can use the command line, as follows:

sqlcmd -S myServer\\instanceName -i C:\\myScript.sql -o C:\\log.txt


This is useful when you do a wrong insert and the ID of your nice table gets messed up. I hate it... so of course for when I need to manually correct this (little note for myself).

To get the current last ID of your table, issue this command:


To reset it, to let say 77:
DBCC CHECKIDENT (yourtable, reseed, 77)

See also: RESEED Post in the SQL Authority Blog