views:

240

answers:

1

Hi,

This one is causing me a few nightmares as I'm on the live box trying to work out what is going wrong!

If someone accesses our ASP.Net MVC website with the full URL http://www..net all is OK. If they go to: http://.net then our custom error page is shown. This used to work OK before we moved the site to MVC.

We do have an Application_OnError event in the Global.asax but I know that is not being hit in this situation, as I log to the event log and that is not happening.

If I switch custom errors off in the web.config, the site behaves correctly!

We're using the MVC Beta at the moment. Edit: We're running on IIS6 and using the MVC routing for friendly URLs.

This is impossible to test locally which is fustrating as it only happens on live without the www. I wonder if it is something to do with routing......

Thanks!

+2  A: 

The problem is too vague at this stage for me to be able to give you a good answer but I would look firstly at your URL rewriting - what version of IIS are you using? If IIS5 or 6, are you using Isapi Rewrite? This could be interfering with your response.

As for why the error goes away when you turn customErrors off, well, I have no idea sorry.

On a side-note, if you're concerned with Google ranking, you may want to use a rewriting tool (like Isapi Rewrite and I think built-in to IIS7) to send an automatic redirect (HTTP 301 response) that will send users from the non-www version to the www version. Google sees both of these as individual sites with duplicate content and this will dilute your Page-Rank. This will also avoid the problem you're experimenting altogether as users will only ever see the www version.

Also, I'm not sure if Application_Error is really the best way to deal with errors in ASP.Net MVC. Do some research into the HandleError Action Filter as this to see if this might provide you with a better approach to error handling. Check out Scott Gu's post on this for more info.

I hope this helps. Cheers, Zac

Zac
Hey, good advice on the Google tip.I think I agree with your last para. We're slowly moving things over to MVC and trying to follow best practice. I think the current issue is definately with some MVC routing which ended up hitting our Custom 404 logic throwing an error.
Perhentian