Note to Self - Generating HTTP 500 Internal Server Error Custom Response #

Returning HTTP 500 internal server error as your web service / asp.net REST responses in case of failures may  sound like an odd idea but it has its merits; with handlers and load balancing environments where you want your intelligent routing devices to redirect request to a different server based on an HTTP header response, this approach can come in handy.

In order to return an HTTP 500 server error custom response, there are two simple ways to achieve it.

By throwing an HTTP exception

throw new System.Web.HttpException(500, "Internal Server Error");

 

Or by modifying the headers.

       HttpContext.Current.Response.Status = "500 Internal Server Error";

       HttpContext.Current.Response.AddHeader("Status Code", "500");

       HttpContext.Current.Response.End();

Looking at the response from the HTTP headers, they are almost identical. The only difference is that due to termination of response stream in the later case, the content length is 0.

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://localhost:17109/HTTP500Test/Service.asmx?op=ThrowHTTPException

Content-Type: application/x-www-form-urlencoded

Content-Length: 0

 

HTTP/1.x 500 Internal Server Error

Server: ASP.NET Development Server/9.0.0.0

Date: Fri, 30 May 2008 15:58:24 GMT

X-AspNet-Version: 2.0.50727

Cache-Control: private

Content-Type: text/plain; charset=utf-8

Content-Length: 152

Connection: Close

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://localhost:17109/HTTP500Test/Service.asmx?op=ResponseHeader500Error

Content-Type: application/x-www-form-urlencoded

Content-Length: 0

 

HTTP/1.x 500 Internal Server Error

Server: ASP.NET Development Server/9.0.0.0

Date: Fri, 30 May 2008 15:57:10 GMT

X-AspNet-Version: 2.0.50727

Cache-Control: private, max-age=0

Content-Length: 0

Connection: Close

 

The similar result can be achieved by throwing an ApplicationException or custom exception as well because for the runtime, it still means an internal server error.

The source for the web service project can be downloaded from here. HTTP500Test-Src.zip (2.79 KB)


5/30/2008 8:04:48 AM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

Review for UCertify M70-526 C# Exam. TS Microsoft.NET Framework 2.0 Windows based Client Development.#

With the rapidly changing horizon of upcoming tools and technologies, technical certification is an organized way of studying and keeping oneself up-to-date with the latest and greatest features which software frameworks have to offer.  Even though hands on experience is an absolute necessity, usually when using a particular framework in everyday job, a developer only gets exposed to a smaller set of features pertaining to the task at hand. On the contrary, certification study provides a breadth first approach to the general underlying framework, its mechanics and features. Since it covers a much broader area, studying for a certification exam becomes a daunting task; luckily not for those equipped with tools such as uCertify’s certification study products which allow you to focus your study in the key areas and provide you with instant feedback and help during the preparation process.

uCertify’s 70-526 – C# Exam. TS Microsoft.NET Framework 2.0 Windows based client preparation tool assists you to get ready for the test in a well organized and effective way. It consists of three practice tests with 35 well diversified questions, flash cards, adaptive tests, a detailed study notes section and final exam with 40 questions. This product lets you evaluate your readiness level, provides you a test history to ensure the progress and also allow you to create a custom test, based on the areas you find yourself not so strong. The product is customizable and allow you to create your own entries for test preparation but I believe the sections such as How To’s  could have been expanded and made more effective.  A test can be conducted in both “test” and “learning mode”; detailed explanation and references are provided in the later mode for follow up and understanding. The preparation engine is also equipped with features such as bookmarking, tagging and rating the questions.

Having taken the tests in the classical way, by using Microsoft courses, MSDN and books for prep, I find uCertify’s product quite relevant and helpful. Looking back if I’d have to prepare for the future exams, I’d use this tool in association with recommended text to help gauge the learning.

For details and trial downloads, please visit UCertify's website.


5/28/2008 5:42:47 AM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

My Sessions @ Upcoming SoCal Code Camp in San Diego - 28, 29th. June#
Southern California Rock & Roll Code Camp is being held on June 28th and 29th at University California San Diego Extension. I'll be presenting following three sessions at the code camp.

  • Aspect Oriented Programming in .NET, an Introduction with ASPECT.NET

    Aspect Oriented Programming (AOP) deals with factorization in code i.e. separation of common concerns, specifically cross-cutting concerns, as an advance in modularization. AOSD has been a popular trend in development for quite some time in other programming environments and IDE’s however it’s scope and exposure is limited among .NET developers. This session is focused on getting developers a deeper understanding of what AOP is all about and how to use it in their everyday development. Aspect.NET is the framework used for this presentation.

  • Collaborative Filtering 101 – An Introduction with SQL Server 2008 BI

    "We have recommendations for you!". How do movies, social networking, books and e-commerce websites make recommendations? What algorithms and techniques are used behind the scenes?. In this session we will discuss collaborative filtering. Collaborative Filtering (CF) is defined as profiling or classification of information based on specific entity relationships i.e. making automatic predictions (filtering) about the interests of a user by collecting likelihood information from many users (collaborating). The underlying assumption of CF approach is that those who agreed in the past tend to agree again in the future. For example, a collaborative filtering or recommendation system for music tastes could make predictions about which music a user should like given a partial list of that user's tastes (likes or dislikes).

  • Using ASP.NET MVC to build a blogging engine in 60 minutes or less.

    MVC is a framework methodology that divides an application's implementation into three component roles: models, views, and controllers. ASP.NET now has built-in support for MVC style development and this session is an introduction to using this technique for building a sample application, a blogging engine. This session will elaborate on differences between traditional ASP.NET post-back style development versus the routes and REST architecture based thinking around MVC.


Hope to see you there.

5/3/2008 5:17:08 PM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

Yes, ASP.NET Scales just fine. #

This is a TIP, Twitter Initiated Post. Yes, the following message from Scott Hanselman was the tipping point for me to write this.

“ 4 of the 10 largest sites on the internet are ASP.NET. Live.com (#3) MySpace.com (#5) MSN.com (#7) Orkut (#10)”

This weekend at a social event, friend of a friend (fof) brought up an interesting topic; their company which shall remain nameless is moving away from ASP.NET / SQL / Win 2K3 to JSP / JBOSS / MySQL / Linux platform because apparently someone have told them that ASP.NET does not scale. Also, they have been having slowness issues with their website during the time of high traffic. They are in movie business so slowness during high traffic means loss of revenue when people cannot buy tickets and have to go for alternatives. But of course it has nothing to do with the underlying technology so I had to ask the obvious, "Was it designed to be scalable?"

A prototype which works on two machines may not be the perfect solution for large scale websites when no single point of contact can be a bottle neck, you have to make sure that the connections are handled properly and threads are available when needed.

So I had to defend the ASP.NET honor, counter that false belief therefore I tried explaining to the fof that this view about ASP.NET being unsuitable for enterprise systems is completely untrue. ASP.NET scales just fine, and that’s why four out of ten largest sites are in ASP.NET despite the fact that other platforms have been around longer and competing with free is a lot harder even with all the ROI results you can get. So it might be the configuration, connection pooling, number of open thread or a multitude of different issues which might be causing the problems they are having and can easily be resolved by an independent review.  Also, these issues can happen with any platform. I hope I am not starting a religious war here between .NET and Java web technologies but the truth is, they are both equally fine. Being a developer focused on Microsoft technologies, I have my personal bias towards ASP.NET. I have seen it working perfectly and there is enough empirical evidence to back up this claim. Some of the good ASP.NET optimization tips can be found here.

And here is an excellent Morgan Stanley guide on Internet Trends describing this and other zeitgeists; must see.


4/28/2008 10:27:04 PM (Pacific Standard Time, UTC-08:00) #    Comments [3]  |  Trackback

 

The Square Root of Three by Dave Feinberg#
The Square Root of 3

I’m sure that I will always be
A lonely number like root three

The three is all that’s good and right,
Why must my three keep out of sight
Beneath the vicious square root sign,
I wish instead I were a nine

For nine could thwart this evil trick,
with just some quick arithmetic

I know I’ll never see the sun, as 1.7321
Such is my reality, a sad irrationality

When hark! What is this I see,
Another square root of a three

As quietly co-waltzing by,
Together now we multiply
To form a number we prefer,
Rejoicing as an integer

We break free from our mortal bonds
With the wave of magic wands

Our square root signs become unglued
Your love for me has been renewed


4/27/2008 6:23:49 AM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

Model View Controller Song#
Model View, Model View, Model View Controller
MVC’s the paradigm for factoring your code,
into functional segments so your brain does not explode.
To achieve reusability you gotta keep those boundaries clean,

....

It's a good one!

4/19/2008 1:31:46 PM (Pacific Standard Time, UTC-08:00) #    Comments [3]  |  Trackback

 

Linkapalooza :: April 2008#
Yahoo! Research Projects
The Next Generation of Neural Networks

Aspect Oriented Programming: Radical Research in Modularity

Externalizing web Service Documentation


4/7/2008 9:22:00 PM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

Total Lunar Eclipse Pictures - 20th Feb 2008#
Dr. Eric Ackerman, director of MS program at NSU was able to capture some amazing images of total lunar eclipse today. Check out the photos here especially the ones with the ray of green light; this is what he had to say about it.

"You can see a couple of images where I caught the momentary ray of green light from the Southern pole of the moon which is extremely difficulty to catch.  I was shooting at 6 frames per second during this exact time and the images with the rays of green light were caught in a couple of frames out of 300 images taken"

Great work doc!


2/21/2008 1:09:47 AM (Pacific Standard Time, UTC-08:00) #    Comments [0]  |  Trackback

 

All content © 2008, Adnan Masood
About the Author
On this page
Calendar
<May 2008>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Blogroll OPML