views:

39

answers:

2

I have an HttpHandler class (implements IHttphandler) where the path defined for the handler in web.config is *.jpg. I am requesting a Jpg image in my page. Within the HTTP Handler I am writing to a file in the filesystem. By mistake I was trying to write to a non existant directory. This should have thrown an exception but the execution simply proceeds.Ofcourse no file is written. But if I give a proper directory the file is written correctly.Is there anything special about HttpHandler Exceptions. See part of the code

 public void ProcessRequest(HttpContext context){

        File.WriteAllLines(context.Request.ApplicationPath+@"\"+"resul.log",new string[]{"Entered JPG Handler"});

If I put a breakpoint on the File.WriteAllLines statement and then step over it I can see an exception occurring.

A: 

ASP.NET might only be intercepting ASP.NET file extensions like .aspx and not processing other types of content (i.e. maybe your jpegs are being skipped altogether).

These are the regular file extensions mapped to ASP.NET for processing.

You might have to map other file extensions (like .jpeg, .jpg, etc) in IIS to the ASP.NET processor - This Microsoft article tells how.

John K
A: 

Request.Application returns the application's virtual application root path on the server. For example: "/YourApp", as opposed to "C:\inetpub\wwwroot\YourApp."

What's likely happening is File.WriteLine(...) is actually writing the file somewhere, probably in the same folder as your web server process.

EDIT: Here's some of the likely places to check:

  • if using built-in VS2008 web server

    C:\Program Files (x86)\Common Files\microsoft shared\DevServer\9.0

  • if using built-in VS2010 web server

    C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0

  • if using IIS

    C:\Windows\System32\inetsrv or C:\Windows\SysWOW64\inetsrv

Craig