Monday, April 28, 2008

Spring.NET on Mono

It's been a while since my last post because I've been extremely busy hacking away to get Spring.NET working on Mono. I've basically got a working solution now so we should hopefully get the changes committed back into the Spring.NET repositories in the next couple of weeks.

It's been a bit of an interesting road so far - transistioning our application onto Mono - and I am a bit surprised at how many framework bugs I've discovered. I've submitted one patch so far for a very minor bug in the TypeDescriptor class, however I still have three more patches to write and submit at this point. I wouldn't have thought that the parts of the framework we are using were especially esoteric but perhaps I'm wrong.

Now all I need is stepping debugger integration in MonoDevelop and I won't have to boot into Vista ever again!

Labels: , , ,

Monday, April 21, 2008

Compiling for .net 1.1 framework without VS 2003

I got asked about this by a collegue the other day and it amazed me how many people seemed to be asking the same question on the internet with no helpful answers. The standard response seems to be you need some thing called MsBee!?

No you don't

You have the only tool you require already installed on your workstation, specificlly csc.exe aka the C# compiler.

All you need to do is open a command prompt and set your path:

path=%path%;c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322

and then compile your project:

csc /target:exe out:myprogram.exe *.cs

If your project structure is too complex for a simple command line compile then I suggest you learn a decent .NET build tool.

Labels:

Monday, April 14, 2008

Mapping a view with Nhibernate

Something we've come up against in the last week is a need to map a view in Nhibernate. We have a reasonably complex data model with a hierarchical structure involving about four different tables that we wanted to represent as a single mapped entity in our object model. The obvious approach was to define the appropriate view and map that.

No joined tables in Nhibernate:

There seems to be some confusion on the web with a lot of people complaining that Nhibernate doesn't yet support the joined tables syntax that is available in Hibernate 3.0. While this is true, it doesn't prevent you from working with a database view as long as you don't need to update the underlying tables via Nhibernate.


The solution:

Map the view just as you would map any other table in your data model with the standard syntax:


<class name="MyEntity" table="MyView"/>

The only other change you need to make is in your property mapping. Add the update and insert attributes to ensure Nhibernate doesn't try and generate insert and update statements for your view.


<property name="MyProperty" type="String" column name="MyColumn" length="300" sql-type="varchar" not-null="true"update="false" insert="false"/>


That is probably obvious to most people, but there seemed to be enough confusion when I was searching about it that it seems worth stating it again here.

Labels: ,

Thursday, April 10, 2008

Great SEO newbie checklist

The great content just keeps coming over at SEOmoz. Danny Dover just posted The Beginner's Checklist for Learning SEO. It looks like a fantastic resource for people new to SEO and, as one of those people myself, I will be utilising it to it's full potential!

Great work, keep it coming guys!

Labels:

Tuesday, April 08, 2008

The zen of problem solving.

Sometimes I can be an angry coder. I get stuck on a problem I convince myself ought to be trivial and I get extremely worked up to the point where I feel like breaking something. This happened to me tonight when I was trying to figure out why a custom ASP.NET server control wasn't working as expected.

Long story short - I spent an embarrassing amount of time thrashing around on the net trying to find answers to a non existent problem. Two minutes, literally two minutes after I'd given up and had packed up for the night I realised what the problem was!

The answer was to simply step back a bit from the problem and relax. The lesson: Bring a little zen to your problem solving and you're likely to be a far more productive and stress free programmer.

And no, I'm not going to tell you what the problem was - it's simply too embarrassing.

Labels:

Sunday, April 06, 2008

Url Rewriting and the dreaded "Cannot use a leading .. to exit above the top directory"

I've just had a fun couple of hours trying to figure out why my site suddenly starting giving me this exception:

Exception type: HttpException
Exception message: Cannot use a leading .. to exit above the top directory.

It turns out that ASP.NET 2.0 doesn't like playing nicely with Url Rewriters. The problem occurs when the rewriting rebases the form action path. e.g instead of having your form tag look something like this:

<form id=form1 method="post" action="page.aspx?id=whatever" name="form1">

After rewriting it ends up looking like this:

<form id=form1 method="post" action="../page.aspx?id=whatever" name="form1">

This obviously is not a good thing. For a detailed breakdown of the problem I suggest you read sgerz's post Get GoogleBot to crash your .NET 2.0 site.

In my particular case I am using an open source url rewriter solution from http://urlrewriter.net. Of course the beauty of it being open source is that you can fix the problem! So a one line change on line 80 of HttpContextFacade.cs from:

HttpContext.Current.RewritePath(url, false);

to

HttpContext.Current.RewritePath(url, true);

solved the problem.

So why did this start happening all of a sudden? I can only surmise that it had something to do with the fact that I had just installed Vista SP1 and that caused cassini to start behaving as IIS 6.0 does.

I'll be emailing the maintainers of the project to see if they want to make the change to the main repository.

Labels: , ,

Saturday, April 05, 2008

Png images and ASP.NET... Getting a "A generic error occurred in GDI+"?

Another one I would have spent hours on was solved in two minutes by the wonder that is the internet. More specifically Chris Garrett over at ASPAlliance explains the solution to the png generic error in GDI+ exception .

The short story is you can't use the Bitmap Save() method with a non-seekable stream. So, instead of just doing this:

img.Save(context.Response.OutputStream, ImageFormat.Png);

You have to do something like this:

MemoryStream memoryStream = new MemoryStream();
img.Save(memoryStream, ImageFormat.Png);
memoryStream.WriteTo(context.Response.OutputStream);

Cheers Chris, you saved me hours of work!

Labels: ,

Wednesday, April 02, 2008

Where's the SEO advice for startups?

I read a blog post today that really resonated with me. Rand points out that a lot of startup advice doesn't mention SEO. As someone trying to get a new startup off the ground I've been giving a lot of thought to how best to market it. Now we don't have much money to spend on traditional marketing, and as we are a web based business it makes sense to do most of our marketing on the web. How come others don't consider SEO when planning their marketing campaigns?

I've seen other online businesses cover every bus stop around with expensive advertising, plough money into radio and print, and still not rank on first page in google.

In the world of internet where there are such low barriers to entry (building a website is comparatively cheap compared to starting up a bricks and mortar business) and you are going to be playing in a crowded market place - what are your differentiators?

Will you be ignoring SEO?

Labels: