2011-09-17

I have been developing a web application on my local machine for some days now using Visual Studio 2010. Last night I deployed my application on IIS 7 and frustratingly stumbled across a major show stopper. The problem is related to error handling in Ajax request. To begin with I have some edit screens which works on ajax request. Here is the what the ajax part of the Ajax edit screen looks like.

I was relying on the "onError" callback of the above Ajax.BeginForm(). So in my controller, whenever I wanted to display error to user (model error or any other error), I just set the Server Response to 500 (Internal Server Error) optimistically hoping that this would result in "OnError" handler of Ajax.BeginForm() being invoked. Here is a snippet of how I did this in my controller.

As can be seen from above code, I returned PartialView and if it contained Model Errors, they will automatically get displayed on the Ajax Edit Screen. Then in the "OnError" JavaScript I just replace the related div with the PartialView returned by the controller something like this.

This all worked great on my development machine. When I deployed my application on IIS 7 and accessed it from an windows XP box (with IE 8 or Chrome), instead of PartialView, the browsers just displayed the default "500 Internal Server Error" screen. So I have a few doubts that caused me not to sleep well last night.

Is the approach that I have used for Ajax editing a reasonable one. If not what could be the other way(s) I could have handled Ajax Editing (with ability to display model errors).

Since I been developing these modules for some days now and have put up considerable effort, is there any work arounds to get it working on XP box. Basically, it would be ideal if I could somehow prevent browser from displaying their default "500 Internal Server Error" screen.

Is this approach working on windows 7, because I have IIS 7 installed on the same windows 7 machine that I am using to browse to site, or its just that it works well with windows 7.

If any other suggestions, please go ahead.

Edit:
I have found the workaround for my problem. So that means doubt no 2 and 3 are answered. Basically the following entry in web.config prevents the browser from showing up default browser pages for the website.

But that still leaves out my first doubt. Have I used a reasonable approach to Ajax editing ?

Show more