Sunday, February 07, 2010
Fiddler is a great tool for inspecting HTTP traffic. If you’re building a web services based application or AJAX intensive web application, you’ll need to check this out. Fiddler has been around for a long time and there’s a lot of good content out on the net about how to use this. There are several gotchas with this tool – like how is behaves with local addresses (i.e. localhost, 127.0.0.1, etc.). Be sure to read up on all of that if you’re new to Fiddler.
One lesson I learned today while playing with the latest CTP of ADO.NET Data Services, is disable IPv6 in the Fiddler options. Having this enabled seems to result in “Connection to localhost failed. <BR>Exception Text: No connection could be made because the target machine actively refused it” errors for local addresses. Like so:
Disable IPv6 in the Fiddler options seems to solve this.
Looks good now:
Hope this helps someone else out there
Wednesday, February 03, 2010
Monday, February 01, 2010
Are you getting 404’s on your deployed site when it works perfectly on your development machine?
There’s a number of hidden gotchas when deploying an ASP.NET MVC application to a shared hosting providers. My provider of choice is Webhost4life.com. Here’s a list of issues I ran into and the solutions for each.
IIS 6.0 vs IIS 7.0
There’s a number of issues you need to be aware of here. If you using IIS 6 -- and if you’re on Webhost4life there’s a good chance you are – then you need to make sure you’re virtual directory is configured w/ the “Wildcard application map” ISAPI setup that Phil talks about in his ASP.NET MVC on IIS 6 Walkthrough post. The short answer is – you have to contact Webhost4life to do this. As of this writing, this is not available through their Control Panel.
MVC Binaries
As of this writing, Webhost4life.com does not have ASP.NET MVC installed on their servers and therefore none of the assemblies are installed in the GAC. At a minimum, you need to bin deploy System.Web.Mvc.dll assembly. Follow the instructions from Phil on how to do this in his post Bin Deploying ASP.NET MVC – the abbreviated version is: mark the references to MVC assemblies in your project as CopyLocal=true.
Route Setup
Make sure that your routes our setup in a way that jives with your domain. In other words, make sure that http://www.yourdomain.com/ will go to the proper route. This is easy to overlook since your Startup Page in Visual Studio is set to something like /Site/Home while debugging. However, this isn’t how people are going to navigate to your site on your hosting provider. In my case I setup routes with the code below. This allows folks coming into my site via http://yourdomain.com and http://yourdomain.com/Site/Home to all end up in the same place
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Site", action = "Home", id = "" });
routes.MapRoute("Root", "", new { controller = "Site", action = "Home", id = "" } );
}
protected void Application_Start()
{
Global.RuntimeSettings = new RuntimeSettings {MachineName = base.Context.Server.MachineName};
RegisterRoutes(RouteTable.Routes);
}
}
Link Round Up
Here’s a list of things I found helpful when debugging this stuff
Thursday, January 14, 2010
The only thing worse than my XPath skills are my RegEx skills. I don’t use XPath all that much these days, but today I needed to. It took me a while to find a code sample that does this. After a playing a bit with SnippetCompiler, I found the solution:
StringBuilder builder = new StringBuilder();
builder.AppendLine("<foo>");
builder.AppendLine("<bar baz=\"a\">1</bar>");
builder.AppendLine("<bar>2</bar>");
builder.AppendLine("<bar baz=\"b\">3</bar>");
builder.AppendLine("<bar>4</bar>");
builder.AppendLine("<bar baz=\"c\">5</bar>");
builder.AppendLine("</foo>");
XmlDocument doc = new XmlDocument();
doc.LoadXml(builder.ToString());
XmlNodeList nodes = doc.SelectNodes("//foo/bar[not(@baz)]");
if ( nodes == null )
{
WL("nodes was null");
}
else
{
foreach ( XmlNode node in nodes )
{
WL("Node: " + node.InnerText);
}
}

Wednesday, January 06, 2010
Registration is up, and I have my fingers crossed that my company will be able to send me this year. Here’s the sessions that look interesting to me:
Thursday, December 10, 2009
I’m creating a simple ASP.NET MVC application and on first run I’m getting blasted with this:
Google didn’t turn up the solution as fast as I would have liked, so I thought I’d post it here for the next fool to find :)
Solution:
When you add a Silverlight project to a solution, Visual Studio will ask you if you would like to create new web site to host it, or choose an existing one in your solution. I choose an existing one. By default, Visual Studio creates this in your HTML markup to host a Silverlight application:
<div id="silverlight">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2">
<param name="source" value="ClientBin/MySilverlightApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="page=UserRegistrationView" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
<iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>
Visual Studio does not account for the URL rewriting that comes with MVC and by default the path to xap file is wrong. Change the source parameter to be rooted like so:
<param name="source" value="/ClientBin/MySilverlightApp.xap"/>
One simple slash should fix your problem. Hope this helps someone else (you’re not a fool :)
Wednesday, December 09, 2009
I find Internet Information Services (IIS) Manager v6.1 that ships with Windows 7 extremely difficult to use. It’s good looking, but the usability is terrible. I can never find what I’m looking for.
I installed DotNetNuke this morning and wanted to play around. For the life of me I could not find where to change the application’s App Pool. This is very straightforward in previous versions, but this seems very hidden to me in v6.1. The only way I found to do it is to click on the “Basic Settings” in the Actions panel on the far right:
From there, you get a familiar dialog
Wow that was frustrating. I was literally spent 30 minutes hunting through the help file and Google’ing but found nothing. I really wish I could have the old IIS Manager back. Ever since Vista, this thing has been impossible to use :(
Monday, November 23, 2009
The debugging experience in Silverlight project using Visual Studio is quite good. However, there are two things that is doesn’t help much with: when data bindings don’t work, and when your XAML doesn’t look like you think it should. Here’s a post about debugging data bindings. The visual part is a little more involved. Yes, yes Expression Blend has a nice visual designer, but it’s fairly common for Blend to show a piece of XAML in one way and for it to actually render in the browser differently (sometime significantly differently). Today I found First Floor Software’s Silverlight Spy. This appears to be a pretty awesome diagnostics tool that allows you to see and alter Silverlight’s Visual Tree at runtime side by side an embedded browser.
You can edit the Visual Studio within Silverlight Spy and see the rendered content change immediately. This is extremely useful. This is to Silverlight apps what Firebug is to web apps.
If this is still useful at the end of the trial period, I’ll be buying a copy of this for myself.
I spent well over an hour on Friday with this one and gave up. I spent almost another hour today working on this. I almost gave up, but when I’m in learn-mode like I am with Silverlight, these types of issues can really teach you a lot if you see them through. I had a ComboBox with bindings on it’s ItemSource and SelectedItem like so:
<ComboBox Name="ComboBoxControl" Style="{StaticResource ComboBoxStyle}"
SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
ItemsSource="{Binding Path=Options}"
IsEnabled="{Binding Path=IsReadOnly}"
Foreground="{StaticResource SemiDarkTextBrush}"
Height="22" Width="150" Grid.Column="1" Margin="30,0,10,0" HorizontalAlignment="Stretch" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Foreground="{StaticResource SemiDarkTextBrush}"
Text="{Binding Path=Label, Mode=OneWay}"
TextWrapping="Wrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I put breakpoints in my model’s SelectedOption property and I could see Silverlight calling it. So, I knew there were no hard binding errors. The bindings were working, except… they weren’t. The ComboBox always showed up with no selected item. I kept plugging away, and by accident I discovered the order of the binding occurrences matter. Changing the markup to define the ItemsSource binding before the SelectedItem binding solved the problem. Like so:
<ComboBox Name="ComboBoxControl" Style="{StaticResource ComboBoxStyle}"
ItemsSource="{Binding Path=Options}"
SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
IsEnabled="{Binding Path=IsReadOnly}"
Foreground="{StaticResource SemiDarkTextBrush}"
Height="22" Width="150" Grid.Column="1" Margin="30,0,10,0" HorizontalAlignment="Stretch" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Foreground="{StaticResource SemiDarkTextBrush}"
Text="{Binding Path=Label, Mode=OneWay}"
TextWrapping="Wrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Wow, that’s pretty nasty. I’m lucky stumbled on the solution. I consider this a bug.
Hope this helps someone else out there
I’ve been neck deep in Silverlight development for the last couple of weeks. I’m finally starting to feel somewhat competent. Most of my struggles have been with XAML in general, so I think the steep learning curve applies to both Silverlight and WPF. One of the things I’ve been using struggling with the most is troubleshooting data bindings. The data binding system in Silverlight and WPF is pretty awesome, but it’s definitely not intuitive nor discoverable. When you force yourself to learn it, most of those issues melt away, but… buuuuut, debugging binding remains extremely difficult.
Today I discovered something that helps a TON. Binding errors are written to the Visual Studio Output Window! Check this out:
It’s not the most robust solution, but it’s definitely workable.
After discovering this, I did a bit more Googling around and found this handy article: How can I debug WPF bindings. He covers the Output Window approach there as well. For the record, I was not able to get the “Trace Sources” technique to work in Silverlight – only WPF.
Hope this helps someone else out