Skip to main content


Showing posts from June, 2013

C# Console app that displays twitter feed using Linq To Twitter (using Single User Authorization)

I recently had to add a twitter feed to my existing ASP.NET MVC 4 application. All I had to do was pull the last 10 tweets for a given user. It took me a while (shamefully, 3 hours) to get it working so I thought of writing a simple tutorial that explains how to pull a twitter feed for a console app using LINQ to Twitter.

LINQ to Twitter is an open source 3rd party LINQ Provider for the Twitter micro-blogging service. It uses standard LINQ syntax for queries and includes method calls for changes via the Twitter API
What took me long to figure out was the way twitter has implemented authentication using OAuth. Before you do anything, make sure you read the Learning to use OAuth document.
In my example, I used Single User Authorization. Single User Authorization is designed for scenarios where you'll only ever have one account accessing Twitter. i.e. if your Web site does periodic Twitter updates, regardless of user or you have a server that monitors general information. 
Before we be…

ASP.NET MVC: Error after switching on compilation of views

Its always a good idea to compile your Razor views. The reason being that errors within a view file are not detected until run time.

To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the project file and set the MvcBuildViews property to true, as shown in the following example:

After enabling MvcBuildViews I started seeing unseemly errors like so:

error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.
I couldn't figure it out but a colleague soon pointed out the following resource:

Turns out that this problem occurs when there is web project output (templated web.config or temporary publish files…

Deploying an ASP.NET MVC Application using Powershell

Personally, I'm not a big fan of batch files. Don't get me wrong, while batch files are super cool at getting things done, I personally prefer the flexibility that powershell provides.

The script shown below can be used as a template to automate the website deployment process.
I have however assumed that you have MVC installed on the machine. If you do not, then you will need to add the dlls necessary to bin deploy MVC.  There are a set of assemblies you’ll need to include with your application for it to run properly, unless they are already installed in the Global Assembly Cache (GAC) on the server. Have a look at script leverages the appcmd utility. You need to be mindful that: When running the script, you may need to set your execution policy.When running this script using other automated deployment environments you may only have access to the command line so you can invoke it like so: cmd /c powershell -E…