Monday, May 12, 2008

.ashx files don't like blank output

Interesting - in the case of blank output, a regular .NET web page (.aspx) just outputs nothing to the screen, but a generic handler (.ashx) throws this:

"XML Parsing Error: no element found"

The generic handler I was working on was supposed to evaluate where the request was coming from, then do some processing and redirect. This worked fine until I uploaded it live. Turned out my code to evaluate the referrer was not looking for the correct live path. An easy fix, except that the misleading error lead me astray and had me checking .ashx permissions and Win 2k3 settings.

I finally converted the page back to a .aspx page, and the code returned a blank page, so I was able to quickly find the error after that. Once I corrected the path on the .ashx page, everything worked fine.

BTW, .ashx files have less overhead than regular .aspx pages, since they're not set up to serve up full web pages, so they're great processing-only pages, and non-html output like XML. More info here:
http://www.aspcode.net/Creating-an-ASHX-handler-in-ASPNET.aspx

3 comments:

Unknown said...

thank you a ton!!! wasted 2 days after it as i neva worked with handler before..dammm....

Unknown said...

I'm glad the post was helpful.

.Net is usually fantastic, but sometimes they really leave you hanging with very cryptic errors.

Anonymous said...

Dude, thanks so much for your post. The penny dropped once I thought about it, and I'd even ready your post a few times (and every other on google).
I had an error in my app that was not being caught, no content generated so get this stupid xml error. It's pretty pathetic really on MS part, just send us off on wild goose chase checking handlers, config files. (mad)

Regards, Patrick S.