Customising the debug and run an ASP.NET MVC Application

I tend to use F5 to debug my code, my two teammates have a preference to have the codebase as a virtual directory in IIS and make changes to their code in Visual Studio and then reload the page in a browser to analyse the returned results.

Which is the better technique? Certainly my co-workers had a  point that by running using Cassini instead of IIS I was opening up myself to bugs popping up when the application was deployed to a real IIS box on testing and some IIS-specific behavior arose.

But why must I hassle myself with attaching IIS to the W3wp.exe process every time I want to do a line-by-line debug my code? And I always want to be debugging, especially in this new realm of integrated ASP.Net MVC where debugging a View means you have to worry about if the bug lies in your ASP.Net code, your JQuery code, or the service(s) your .ajax or .getJSON calls are making. I didn’t mind the hassle of having to recompile every time a change needed to be made inside the Controller or Business Logic layers once it meant I could track the state of my application during events as closely as possible.

Turns out we can have it both ways. These recommendation from Stephen Walter, although set on the topic of running an ASP.Net MVC Application specifically, are useful for any developer looking to customise the debug and run process when using Visual Studio 2008. So my coworkers and I will both be happy, because now they’ll be readily able to debug their code in real time (and engaging in a better coding practice at the same time) and I’ll be running my debug sessions on top of IIS to remove any possible hiccups from using Cassini for testing.

The settings are available on the Web tab on the Web Application Project’s properties page (ASP.Net MVC or not)  and to do this I have to make sure it is set to use a local IIS virtual directory (which I’ll make right there if it isn’t set already) and that I enable the check box that allows me to make code changes without the need to stop debugging and recompile.

HOWTO: VS 2008 Fix for ASP.Net MVC and xUnit.net new project errors

This may have been fixed by now with the release of ASP.Net MVC 1.0 RC, but using ASP.Net MVC Beta 1 to create a new project with xUnit.Net tests always generated the error “The name ‘GlobalApplication’ does not exist in the current context” when you first compile, something a bit daunting to any developer now trying to ‘get’ ASP.Net MVC.

This Codeplex discussion has the answer.

Basically rename all instances of GlobalApplication to MvcApplication in the Test project and things should compile and run fine. If you want to know exactly why this works, you can take a read of this cool article on the anatomy of an ASP.Net MVC Application.

ASP.NET MVC Caching and Compression

Was interested in just how ASP.Net MVC could handle this given that soon-to-be-implemented features to a website I work on is including features such as RSS feeds which are potentially high-bandwidth links to have.

Thankfully I found Kazi Manzur’s Blog article on ASP.Net MVC ActionFilter for Caching and Compression. Quite a good read, hopefully I’ll be able to try out the technique in practice during a subsequent sprint.

Two different approaches to setting up RSS feeds in ASP.Net MVC

I was actually looking for just one way of implementing RSS with ASP.Net MVC Framework as part of a new feature for GigJunkie (look for the announcement in the GigJunkie blog in a few weeks)…I actually was about to implement this

Brad Abrams : RSS Feed with the new ASP.NET MVC Framework.

when I found this:

ASP.NET MVC RSS Feed Action Result
Which method is better is a matter of opinion. In terms of generating a well formed RSS or ATOM document without needing to know too much details about the standard itself, the 2nd link is better since it uses already established Windows Communication Foundation (WCF) objects such as RSS20FeedFormatter, Atom10FeedFormatter, SyndicationFeed and SyndicationItem to wrap your content inside the appropriate tags within the XML document.

However, there are some limitations to this approach as you are trusting these pre-defined objects to adhere to the defined standard and place values in the correct or expected appropriate position within the XML. This can result in some issues, as for example when I realised that unless declared in the constructor as a parameter, I found no property of the SyndicationFeed object that would directly manipulate the value of the rendered <description> tag’s contents of an RSS 2.0 feed. I had assumed editing the SyndicationFeed’s Content property would apply these changes, however they instead created an <a10:content> parameter which contained my content instead. The reason I needed the <description> values edited are because these are what are displayed in Live feeds inside Firefox and Outlook. <a10:content> although inside the feed, is not rendered in any particular way. A slight variation on how I built the content was required, but still, it was a little annoying to have to discover it was an issue in the first place.

So that means there are still merits of using the 1st link’s method, since you as the developer, are in essence, in full control of ensuring that the View renders the proper parameters and that all ViewData is in the appropriate locations within it. This has its benefits, in cases for example where the standard may change or be upgraded before the Framework objects themselves have had a chance to be updated as well. The counter to this is, of course, that you are also fully responsible for a shoddy implementation of the XML specification if you are not thorough with the RSS and ATOM specification guidelines.

Using ASP.NET AJAX with ASP.NET MVC

Using ASP.NET AJAX with ASP.NET MVC.

I thought you couldn’t use them both, given that a ScriptManager control is server side and implementing it would break the design pattern of MVC Apps…turns out the raw Javascript that is used behind the Microsoft Ajax toolkit is available as a standalone download, and by referencing this on the client side View pages one can actually use all the features of Ajax toolkit without breaking the MVC model as you no longer need to have the server side ScriptManager control present.

ASP.NET MVC Videos : The Official Microsoft ASP.NET Site

ASP.NET MVC Videos : The Official Microsoft ASP.NET Site.

Have to translate a user control into something compatible with MVC world, so this is my library for the day…Already started the ‘Create a Task List’ video, and it’s going nicely. Note: Even if you have the full SQL Server installed, in order to create the database the way the video does it you need to have SQL Server Express installed as well.