WebMatrix Beta 3is now available. WebMatrix is a lightweight development environment to enable Razor development, a new syntax for .NET web pages. Lightweight does not mean less features. It is very full featured and cool.
Razor is simple mix HTML and an @ sign to denote C# or VB.NET code. In this quick blog entry I will show you how to build a web page to connect to Twitter and Facebook.
- Startup WebMatrix
- Select Site from Template
- Select Empty Site and name the site HelloWebMatrix
- Click Browser your files
- Click Add a File to Your Site
- Razor uses cshtml for C# HTML or vbhtml for VB.NET html based pages. For now select cshtml and set the filename to Default.cshtml. Then click ok. By the way did you notice that php is supported?
Down the left side you have a list of files. And then in the main area you have the editor with what looks like a HTML web page. The layout is similar to VS.
The web page will end up being a mix of HTML and C#. Now you might be think this could be bad, mixing HTML and code. But it can actually be useful if you think about the web page just being a few. The code you put in should call methods to render additional HTML.
In the body tag you put
@Twitter.Search("#WebMatrix")
Hit run to view the web page. You will probably get an error, "Compiler Error Message: CS0103: The name 'Twitter' does not exist in the current context". What this is telling you is that your site does not know about the Twitter class.
You will need to tell your site about Twitter. To do this go to the admin site, http://yourserver/_admin. The easiest way to get to the admin site is to append _admin. The first time you go to the admin site you will need to create a password. Once that is accomplished the Package Manager is shown. The Package Manager allows you to add packages like the Microsoft Web Helpers which contain the Twitter class or the Facebook package for Facebook. Click "Install package from an online feed.". This will take you to a list of packages you can install. Install the Microsoft Web Helpers and Facebook by clicking the install button for each package. Go back to WebMatrix and hit Run again. You should now see a web page like below.
The Twitter type also includes Profile. Profile will show the profile of a user. For example
@Twitter.Profile("Microsoft")
To add a like button for Facebook put
@Facebook.LikeButton("www.satter.org")
In literally took me longer to write the blog entry than to get a web page mashing up Twitter and Facebook. Have fun using WebMatrix.
Comments