July 2010 Entries

My first Razor (ASP.NET WebPages) based app in WebMatrix

If you are following Scott Gu’s Blog or simply the ASP.NET Community, you would have definitely heard about WebMatrix and the Razor view engine.  More specifically you must have heard of something known as “ASP.NET WebPages”

The ASP.NET WebPages, Razor Engine as well as WebMatrix can definitely be confusing for many who have been into ASP.NET Development for sometime now.  Clearly, this is not for you, if you are hard core ASP.NET Web Developer and are happy with either Webforms or MVC based development.

However, if you are new to ASP.NET and would like something simple and clean (unlike the much more comprehensive webforms/MVC model), you would really want to start with the WebMatrix.  The WebMatrix is a tool that allows you to create web apps in a breeze.  Get an intro from  (more specifically download it along with the Web Platform Installer 3 Beta from here )

Note: Don’t miss to watch the intro video on WebMatrix at  

Having said that, I wanted to explore the WebMatrix tool as well as the Razor engine and to do that, I first downloaded WebMatrix.  Along with it came the Razor engine (ASP.NET WebPages folder in C: \Program Files\Microsoft ASP.NET)

To begin with, I opened WebMatrix and it gave me a nice looking welcome screen.


As you can see, there are quite a lot of options to create site from WebAppGallery (most popular webapps such as DotNetNuke, Wordpress etc.,)


or create site from templates (built-in starter kits to speed up development). 


These, for sure, would speed up your web development to great magnitude if you are starting with ASP.NET Development.

You can also chose to create a “Site from Folder” and chose a location to create your website.  I did that and I got a blank site.  It gave me the link to “Add file to my site” and a variety of file options therein


I chose the CSHTML file type since I would be using C# syntax in my webpage.  What it gave is a regular HTML code block as follows

<!DOCTYPE html>

Now, my friend Janakiram MSV posted a nice status message on Facebook using PHP syntax on, how, when job, passion and hobby are the same, it gives an adrenaline rush.  I really liked the theme and wanted to use that for my first coding experience in Razor based apps in WebMatrix (I have to be careful here since WebMatrix allows you to create not just Razor based apps but even the popular web apps such as DotNetNuke and much more which are not necessarily Razor based)

So, here below is the syntax for the above logic of Jani

<!DOCTYPE html>
var passion = "evangelism";
var job = "evangelism";
var hobby = "evangelism";

<div id="source-of-happiness">
@if((passion == job) && (hobby == job))
{<p>Adrenaline rush !!</p>}

{<p>I hate monday mornings!</p>}


If you are following so far with me (trying it along), you can just click on the “Run” icon in the top and select “Internet Explorer” to run the page.


The output for this obviously would be “Adrenalin Rush” since I have given the same direct string values to all the variables.  But getting this from database isn’t that difficult (would save it for a later post or read Scott Gu's post)

If you notice the syntax above, its all very few lines of code and you can switch between HTML and C# code seamlessly. (I hear experienced guys shout, ah wasn’t this kind of no no in the codebehind days?)

Agreed and this is one more way for developers who like spaghetti coding style.  More over, if you had to do this in a regular ASP.NET Page, you would need chunks of <% or <%= and switching is also not that straight forward.

And not just that.  I can now switch to the “Site” tab (down bottom)


and do a lot of stuff.  For example, I want to add Database or Run a report I can use this screen to do that through a wizard


The “Run a report” uses the free SEO Toolkit and analyzes your site and provides a report on what all you need to fix for your site to the SEO optimized.  All within the same IDE.

I can also go back to the “Site” tab and check the “Requests” for my site and manage the “Settings” as well


Needless to say, it provides a real Integrated tool to do a lot of web development, management and deployment (there is a link to find best web hosting offers as you can see in the previous screen shot.

If you want more comprehensive start up tutorial with Database etc.,  you can check Scott Gu’s post “Introducing WebMatrix” 

That’s my experimentation with WebMatrix and ASP.NET WebPages.  I hope you found it beneficial.

Cheers !!!

Creating and running VS 2010 Web Application Projects and Web Sites on IIS instead of the default Cassini web server

One of the clear changes in Visual Studio from Visual Studio 2005, is the dependency of VS on IIS for creating websites/web applications.  In VS 2005 until its SP1 you only had the choice to create Websites that use the local cassini web server for development purposes.  The Web Application Projects allows you to create the legacy style of project based sites which can run on IIS.

From VS 2008, you can create both Web Application Projects as well as Websites that can run on Cassini i.e. without the dependency on IIS and the ability to create the webapp folder anywhere in your machine(Remember the days when you could only create a webapp on c: \inetpub\wwwroot coz, it required to fall into the IIS WebRoot to be able to run and debug apps locally) 

In VS 2010, the option continues to be the same i.e. by default both Web Application Projects (WAPs) and Website projects don’t have a dependency on IIS.  In fact, to create them on IIS, you need to do a little bit of work around.

Note that in all the following scenarios, we need to run VS 2010 in the context of an administrator since we are creating/running the apps on IIS.  So, it would be important to start VS 2010 (click the start icon, type visual studio 2010 – right click on the list and select “Run as administrator” and click “Yes” for the User Account Control confirmation dialog)

Creating and Running Web Application Projects on IIS on development machine

First off, run VS 2010 as administrator and select “File – New Project” and specify the location to store the project.  I have given c: \inetpub\wwwroot but you can even specify D: or any other location you want to.


Note that even though you created this in the webroot when you run the application as is, it would still chose to use the Cassini Webserver (you can see that the page that opens uses the URL http://localhost::PORTNUMBER as the URL format)

Close the web browser and come back to the Visual Studio IDE.  From the tools menu, select “Project” – “<PROJECTNAME> Properties”

It would list the properties listing in the left and the property values in the right.

Select the “Web” tab in the listing.

In the bottom under “Servers”, select “Use Local IIS Webserver”


At this point, if you try running/building the app, it would alert you stating that the app though configured to run in IIS is not actually configured in the IIS as an application.


Say “Yes”and it would configure your app as an Application in IIS.  Alternatively, before running, you can also click on the “Create Virtual Directory” while selecting “Use Local IIS Web server” in the previous screen.

Now, when you run the app, you will notice that the app is actually running on IIS since the URL would point to http://localhost/APPNAME and discard the port number that comes when running on Cassini.

When you go to the IIS Control Panel, you would also notice that the app is created in virtual directories listing and points to the folder where the physical files are stored (interesting, it automatically does the root folder mapping even though you create a deep folder structure such as E: \Folders\Projects\ProjectName\AppName.

You can use the same approach for migrating existing projects as well to IIS from the cassini web server.

Creating and Running Websites on IIS on development machine

Again, start Visual Studio in the context of an administrator. 

In Visual Studio, select “File – New Website”

In the Web location dialog at the bottom chose “HTTP” instead of the default “File System” and specify a name to your website


That’s all is required in the case of website.  It would automatically configure it to run on IIS instead of cassini as you can see when you run the app.

These steps could become a little tricky and hence thought a post is worth.  Do share your comments/suggestions if any.

Cheers !!

Error Connecting to SQL Azure from Management Studio (Microsoft SQL Server, Error:53)

If you are receiving an error trying to connect to SQL Azure from Management Studio (SQL Server 2008 R2) and the error code indicates Error:53, most likely you are running into the following issue.  Note that, the rest of the post assumes that you have the proper server name / credentials and have configured your IP Address range in the SQL Azure administration portal.


The above error clearly indicates that the connection couldn’t be opened.  One of my colleagues faced this issue and we were pretty sure we had the correct username/password.  We also had enabled IP Address from the portal, so that shouldn’t be the cause.

When we drilled a little bit into it, the issue was with the ServerName parameter.  Earlier, SQL Azure required the servername parameter to be ADMINUSERNAME@SERVERNAME.DATABASE.WINDOWS.NET

Now, we don’t need to specify the ADMINUSERNAME@ part.  We just need to specify SERVERNAME.DATABASE.WINDOWS.NET

Upon correcting this, it started connecting and gave a sigh of relief.  Infact, this change happened quite a few months back but just that, my colleague wasn’t aware and it was too trivial that I didn’t look into earlier.

Nevertheless, if you arrived here searching for this error and it resolved, this post solves the purpose Smile


Updated Windows Azure Tools for Visual Studio 2010 available

Since the commerical availability of Windows Azure, there were a few releases of Windows Azure tools for Visual Studio that had shipped.  Now, there is an updated version of Windows Azure Tools for Visual Studio available.  It is available as Windows Azure Tools for Microsoft Visual Studio 1.2 (June 2010) and can be downloaded from here

This includes support for Visual Studio 2010 RTM as well as Visual Studio 2008 SP1.  Other features include Cloud Storage Explorer, .NET 4 support and few other new things as explained in the download page.

That is for this post.  More to follow in the next posts.

Cheers !!!