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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I don’t have an IIS6 server at hand at the moment, but there are two steps required:
- map the xml extension to ASP.NET (use the executable path from aspx extension): Setting Application Mappings in IIS 6.0
- tell ASP.NET to use your custom handler: Deploying HTTP Handlers and HTTP Modules
The first step is not obvious because the Visual Studio integrated web server is mapping all requests to ASP.NET.
Other resources:
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0