Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.


I would like to intercept any request made to the server for XML files. I thought that it might be possible with an HttpHandler. It's coded and it works... on localhost only (?!?!).

So, why is it working on localhost only? Here is my web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.xml" type="FooBar.XmlHandler, FooBar" />
    </httpHandlers>
  </system.web>
</configuration>

Here is my C# :

namespace FooBar
{
    public class XmlHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse Response = context.Response;
            Response.Write(xmlString);
        }
    }
}

As you might have seen, I'm writing the xmlString directly in the response, it's only temporary because I'm still wondering how I could give the filename instead (that's the second question ;) )

What is supposed to be written in the response is only the xml filename that will be retrieved by a flash app.

Thanks

Details :
Using IIS 6.0 on Windows Server 2003.

Edit :
When calling the page from another computer it looks like it's not getting to the HttpHandler. However, the mapping for IIS have been done correctly.

share|improve this question
    
Your code looks fine. When you say it is not working when not on localhost, exactly what does that mean? What do you see (or not see) that tells you it is not working? How are you calling this? Have you used Fiddler and/or the VS debugger to watch the request? –  Ray Apr 13 '10 at 14:17
    
@Ray : Added details. Does it matter if the assembly is a ASP.Net website? –  ALOToverflow Apr 13 '10 at 14:22
    
It should work as you have set it up. Stefano's point is a good place to check - if IIS is handling the request and not passing it on to asp.net, this is what you will see. Do you see the request in the IIS log? –  Ray Apr 13 '10 at 14:26
    
@Ray : I can see the request in the IIS log file. But I get a 402.1 (SecurityError), 401.1(Not authorized) and finally a 404.2 (File not found). It's kind of weird since if I remove it from IIS Manager I can access the file... –  ALOToverflow Apr 13 '10 at 14:51

2 Answers 2

up vote 3 down vote accepted

I don't have an IIS6 server at hand at the moment, but there are two steps required:

The first step is not obvious because the Visual Studio integrated web server is mapping all requests to ASP.NET.

Other resources:

share|improve this answer
    
Ah. It's good to know that VS automatically maps all requests to the asp.net. Thanks for the summary. It's working now. –  ALOToverflow Apr 13 '10 at 17:08

if IIS is version 6.0 or previous, handler will be ignored, because IIS handle xml extensions without calling ASP.NET process. you can change it from IIS Manager,saying iis to use asp.net for handling XML.

share|improve this answer
    
Yes. The IIS Manager is already configured to handle xml extension with my dll. But still doesn't work. –  ALOToverflow Apr 13 '10 at 14:27
    
IIS should be configured to have asp.net handle xml files, not your dll. COnfigure xml files the same way you see aspx files configured. –  Ray Apr 13 '10 at 14:54
    
How can I define a custom behavior if it's asp.net that handles the xml? –  ALOToverflow Apr 13 '10 at 14:58
2  
When asp.net handles the request, it will use the mapping you set up in web.config to send the request to your httphandler –  Ray Apr 13 '10 at 16:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.