Skip to content

Project Cool - Harish Ranganathan
Syndicate content Project Cool
An ASP.NET Blog
Updated: 8 hours 30 min ago

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

Wed, 07/28/2010 - 22:32

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 www.microsoft.com/web/webmatrix  (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 www.microsoft.com/web/webmatrix  

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.

welcomescreen

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

webgallery

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

webtemplate

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

addfile

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>
<html>
    <head>
        <title></title>
    </head>
    <body>
   
    </body>
</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>
<html>
    <head>
        <title></title>
    </head>
    <body>
    @{
var passion = "evangelism";
var job = "evangelism";
var hobby = "evangelism";
}

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

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

</div>
    </body>
</html>

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.

RunIcon

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)

tab

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

 siteui[6]
 

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

requests

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 !!!

Categories: Blogs

Billion Hearts Beating&ndash;Take the pledge&hellip;after all, you have only heart !

Tue, 07/27/2010 - 18:22

image

Yes, this is an unusual post on the strictly technical blog.  But what I loved about the Billion Hearts Beating campaign is that, it addresses something close to my heart – literally.

One of the common causes of death in the middle age group 30 – 50 (middle at least by Indian norms Smile) is cardiac arrest.  I have seen this happen more often than not for people whom I would have, in my weirdest dreams, imagined of.

You don’t have to be a chain smoker, alcoholic to get cardio arrest.  You can be a teetotaler, non smoker.  But if you are not health conscious, cannot avoid that Mal Pua/Jalebi/Rasagulla (Indian Sweets), you will be surprised, you might well be in the path Sad smile

Another reason I wanted to write about this, is to also give ME the awareness.  Like I mentioned earlier, I am a non-smoker, teetotaler and don’t even eat non-vegetarian.  But can you imagine that over the last 3-4 years, I have literally stopped playing games/working out and that has resulted in way too much extra pounds?

And, I am surrounded by friends who have all the above habits, in addition to temptation to food.  They are even more vulnerable and I cannot imagine of what can happen to them, suddenly.

Cardio arrest (heart attack) can happen even out of excessive stress/anxiety and you don’t even have to be fat/chubby in that case.  So, don’t carry the stress to your bed.   Like they say, don’t take trivial problems too serious.  After all, your life is more important than anything else.

So today, I decide, I will post this non-technical post, for the first time in the last 6 years I have been blogging in the interest that it reaches the millions of readers who visit my blog (check my visitor count)

Go ahead, visit http://www.billionheartsbeating.com/ and take the pledge.  Send it to your friends, share it via FaceBook, Twitter etc.,  After all, its worth than some of the PJs, Celebrity Gossips and other unimportant stuff shared over these places. 

Cheers !!!

Categories: Blogs

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

Sun, 07/18/2010 - 19:00

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.

image

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”

image

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.

image

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

image

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 !!

Categories: Blogs

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

Tue, 07/06/2010 - 13:52

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.

image

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 https://sql.azure.com 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

Cheers!!

Categories: Blogs

Updated Windows Azure Tools for Visual Studio 2010 available

Thu, 07/01/2010 - 16:54

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 !!!

Categories: Blogs

ASP.NET AJAX, jQuery and AJAX Control Toolkit&ndash;the roadmap

Mon, 05/31/2010 - 17:51

The opinions mentioned herein are solely mine and do not reflect those of my employer

Wanted to post this for a long time but couldn’t.  I have been an ASP.NET Developer for quite sometime and have worked with version 1.1, 2.0, 3.5 as well as the latest 4.0.

With ASP.NET 2.0 and Visual Studio 2005, came the era of AJAX and rich UI style web applications.  So, ASP.NET AJAX (codenamed “ATLAS”) was released almost an year later.  This was called as ASP.NET 2.0 AJAX Extensions.  This release was supported further with Visual Studio 2005 Service Pack 1.

The initial release of ASP.NET AJAX had 3 components

ASP.NET AJAX Library – Client library that is used internally by the server controls as well as scripts that can be used to write hand coded ajax style pages

ASP.NET AJAX Extensions – Server controls i.e. ScriptManager,Proxy, UpdatePanel, UpdateProgress and Timer server controls.  Works pretty much like other server controls in terms of development and render client side behavior automatically

AJAX Control Toolkit – Set of server controls that extend a behavior or a capability.  Ex.- AutoCompleteExtender

The AJAX Control Toolkit was a separate download from CodePlex while the first two get installed when you install ASP.NET AJAX Extensions.

With Visual Studio 2008, ASP.NET AJAX made its way into the runtime.  So one doesn’t need to separately install the AJAX Extensions.  However, the AJAX Control Toolkit still remained as a community project that can be downloaded from CodePlex.  By then, the toolkit had close to 30 controls.

So, the approach was clear viz., client side programming using ASP.NET AJAX Library and server side model using built-in controls (UpdatePanel) and/or AJAX Control Toolkit.

However, with Visual Studio 2008 Service Pack 1, we also added support for the ever increasing popular jQuery library.  That is, you can use jQuery along with ASP.NET and would also get intellisense for jQuery in Visual Studio 2008.

Some of you who have played with Visual Studio 2010 Beta and .NET Framework 4 Beta, would also have explored the new AJAX Library which had a lot of templates, live bindings etc., 

But, overall, the road map ahead makes it much simplified.

For client side programming using JavaScript for implementing AJAX in ASP.NET, the recommendation is to use jQuery which will be shipped along with Visual Studio and provides intellisense as well.

For server side programming one you can use the server controls like UpdatePanel etc., and also the AJAX Control Toolkit which has close to 40 controls now.  The AJAX Control Toolkit still remains as a separate download at CodePlex.  You can download the different versions for different versions of ASP.NET at http://ajaxcontroltoolkit.codeplex.com/

The Microsoft AJAX Library will still be available through the CDN (Content Delivery Network) channels.  You can view the CDN resources at http://www.asp.net/ajaxlibrary/CDN.ashx  The versions available in CDN include the 3.5 version as well as 4.0 version of the scripts.  This is specifically to help if you already invested in development using ASP.NET AJAX 4.0 as well as for those who don’t want to use jQuery

Similarly even jQuery and the toolkit would be available as CDN resources in case you chose not to download and have them as a part of your application.

I think this makes AJAX development pretty simple.  Earlier, having Microsoft AJAX Library as well as jQuery for client side scripting was kind of confusing on which one to use.  With this roadmap, it makes it simple and clear.

You can read more on this at http://ajax.asp.net

I hope this post provided some clarity on the AJAX roadmap as I could decipher from various product teams.

Cheers!!!

Categories: Blogs

Unable to update the EntitySet because it has a DefiningQuery and no &lt;UpdateFunction&gt; element exists in the &lt;ModificationFunctionMapping&gt; element to support the current operation

Sun, 05/30/2010 - 20:42

When working with ADO.NET Entity Data Model, its often common that we generate entity schema for more than a single table from our Database.  With Entity Model generation automated by Visual Studio, it becomes even more tempting to create and work with entity models to achieve an object mapping relationship.

One of the errors that you might hit while trying to update an entity set either programmatically using context.SaveChanges or while using the automatic insert/update code generated by GridView etc., is “Unable to update the EntitySet <ENTITY NAME> because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation”

While the description is pretty lengthy, the immediate thing that would come to our mind is to open our the entity model generated code and see if you can update it accordingly.

However, the first thing to check is that, if the Entity Set is generated from a table, whether the table has a primary key definition.  Most of the times, we create tables with primary keys.  But some reference tables and tables which don’t have a primary key cannot be updated using the context of Entity and hence it would throw this error.  Unless it is a View, in which case, the default model is read-only, most of the times the above error occurs since there is no primary key defined in the table.

Once you add a primary key constraint to the table in the database design, there are couple of steps to do until you can resolve the issue

1. Open the EDMX file in the design mode

2. Right click on the design view and select "Modal Browser"

3. The Modal Browser window opens on the right hand side

4. Select the <ModelName>.Store and right click

5. Select "Update Model from Database"

6. It will give you different options to add Tables, Delete Tables and a Refresh tab which mentions a list of database types that would be refreshed

7. If you are just getting the updated model after adding the primary key constraint as in our example, you can directly click "Finish"

8. At this point, we would expect everything should work fine since the primary key constraint is added and the build should be fine to go through

9.  But if you build the solution/project you would receive a "3002 Error" describing that the storage models and conceptual models are not compatible.

10.  You need to manually open the Model1.edmx again.  Right click on the Model1.edmx and select "Open with"

11. Then select "XML (Text) Editor"

12. It will ask you confirmation to close the existing open model.  Confirm by pressing "Yes"

13. This would present you an XML view of the model (I dont know a better way of directly coming to this view, if any post, in comments)

14. Find the section <edmx:ConceptualModels>

15. Under that go the EntityTypes section with the name of the table which you updated with primary key

16.  You will find that under the <Key> collection, additional columns defined as PropertyRef

17. You need to the remove the additional columns and just have the Primray key column within the <Key> section

18.  This is updated in the StorageModel section automatically but not in the conceptualmodel as of today.

19.  Once you make this change and save, you should be able to build the project successfuly and also be able to update it programmatically by code

20. As I write this, I am also raising it in Microsoft Connect as to why the "update model" doesn't do a clean job of updating the schema.  Would post clarifications any, if I receive.

There are other reasons why this error could popup which I am not going into for the sake of simplicity of the post.  If you find something new, please feel free to share it in comments.

Hope this helps.

Cheers !!!

Categories: Blogs

Visual Studio 2010 Winform Application &ndash; Unable to resolve custom assemblies?

Mon, 05/24/2010 - 18:09

Recently I surfaced a problem where, one of my friend had a tough time in getting rid of an assembly reference error.  Despite adding reference to the assembly, while referencing it in code, it was spitting out the “The type or namespace name ‘ASSEMBLYNAME’ could not be found” error.   This was a migration project and owing to the above error, it was throwing another 100 errors.

We tried adding reference to the assembly in other projects and it was not even resolving the namespace while typing out in the using section.

Upon further digging into the error warnings, it indicated something to do with the .NET Framework targeted i.e. 4.0.  My suspicion grew since the target framework was 4.0 and the assembly should be able to be recognized. 

Then, when we checked “Project – “<APPNAME> Properties…”, the issue was with the default target framework which is “.NET Framework 4 Client Profile”

image

By default, Visual Studio 2010 creates Windows Forms App/WPF Apps with the Target Framework set to .NET Framework 4 Client Profile.  This is to minimize the framework size required to be bundled along with the app. Client Profile is new feature since .NET 3.5 SP1 that allows users to package a minified version of .NET Framework that doesn’t include stuff such as ASP.NET, Server programming assemblies and few other assemblies which are typically never used in the Desktop Applications.

Since the .NET Framework client profile is a minified version, it doesn’t contain all the assemblies related to Web services and other deprecated assemblies.  However, this application is a migration app and needed some of the references from Services and hence couldn’t run.

Once, we changed the Target Framework to .NET Framework 4 instead of the default client profile, the application compiled.

Here is link to a very nice article that explains the features of .NET Framework 4 client Profile, the assemblies supported by default etc., http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx

Cheers !!

Categories: Blogs

Visual Studio RTM, Silverlight 4 RTM and WCF RIA Services download links

Wed, 04/21/2010 - 13:04

Its been a long time since I blogged.  Primarily due to Tech Ed India, the ongoing Great Indian Developer Summit (GIDS 2010) and the related travels.  However, here is a quick post with a few updates.  Visual Studio 2010 RTMed in India during Tech Ed.  We had the privilege of having Soma our Senior VP launch VS 2010 RTM in Bangalore, India, during Tech Ed India 2010.   With that we also had Silverlight 4 getting RTMed during the same week.

Earlier I had written posts around using the VS 2010 Beta, RC and the corresponding Silverlight, WCF RIA bits etc., and getting them all to work together.  Now that, both VS 2010 and Silverlight have RTMed, I wanted to post a quick update on the necessary downloads.

Visual Studio 2010 RTM can be downloaded from MSDN Visual Studio site 

If you are doing Silverlight 4 development with Visual studio, then you can download the Silverlight 4 Tools RC2 for Visual Studio 

Then, if you are developing with WCF RIA Services, you can download the WCF RIA Services RC 2 for SL4 and VS 2010

And finally, if you want to use WCF RIA Services in ASP.NET you would require the Domain DataSource control.  Also, to use some of the additional Service Utility tools, you would require the WCF RIA Services Toolkit.  You can download the same from WCF RIA Services Toolkit April 2010

Once you have installed all the above, you should be able to see the following in your add-remove programs

  • WCF RIA Services v1.0 for Visual Studio 2010 (Version 4.0.50401.0)
  • WCF RIA Services Toolkit (Version 4.0.50401.0)
  • Microsoft Silverlight (Version 4.0.50401.0)
  • Microsoft Silverlight 4 SDK (Version 4.0.50401.0)

Also, you would need the Expression Blend 4 for designing the apps for Silverlight 4.  You can download the release candidate from here

Thats it.  You are all set for development with Visual Studio 2010 and Silverlight 4, WCF RIA Services.

Cheers !!!

Categories: Blogs