Wednesday, November 2, 2011

Blank ASP.NET Page

ASP.NET page getting rendered as blank with empty source

This week, I encountered a strange problem with one of my ASP.Net websites. This website is hosted on multiple servers. Upon clicking a link on the home page, the web application takes me to a page. The scenario was working fine on all servers except one. On this particular server, when I tried to browse this page, I would get a blank page. The first thing I checked was the source of the page. The page had the following source:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>

My first guess was that either javascript or html was breaking which was preventing the page from rendering. So, I turned on script debugging in IE. To my surprise, I got no scripting error. The Google search did not yeild anything useful either. The problem was hard to debug because the code was working fine on my local machine and all other servers. I decided to look into the code behind for potential problems. There I found out that in my global.asax file, exception level is handled at application level. In case of any page-level exception, we were propagating the exception to the application level and were displaying a generic error page with exception details. Please note that this problematic page was recently added to our website. Instead of adding it to the top level directory, we added it to a subfolder. So, for this page, the generic error page was present one level up in the folder hierarchy and hence, was unable to locate it. I copied the generic error page to the subfolder and bingo, this time I saw the following generic error page instead of seeing the blank page:

SQL Server does not exist or access denied.

Therefore, the blank page problem was due to IIS unable to locate the generic error page, since it was not there in the subfolder. Hence, the server was transfering itself to a a blank page instead of redirecting me. Once, I copied the generic error page in the subfolder, it was able to locate the generic error page and hence, showed me the actual exception.

So, I resolved one problem but fell into another one. For some reason the server was not able to connect to the database. To resolve this issue, I tried the following steps:

1. Checked the connection string- it was good
2. Increased connection time-out- still not able to establish connection
3. Pinged database server from application server- ping was successful
4. Telnet database server from application server- telnet failed
5. Turned off the firewall on application server for testing- still not able to telnet to the database server
6. Telnet database server from another application server (having no problem)- telnet was successful

The above steps concluded that even though the firewall was turned off on the application server, I was not able to connect to the database server. The only thing then left to check was firewall settings on the database server. It turned out that the firewall on database server was allowing connections with a set of allowed incoming IPs. Upon adding this application server to the list of allowed servers, the application was able to connect and the page started to render fine.