I have a ASP.NET Generic Web Handler (*.ashx) in my Web Application Project. It's path on the web server is /Services/PayPal/IPNListener.ashx
.
IPNListener.ashx
<%@ WebHandler Language="C#"
CodeBehind="IPNListener.ashx.cs"
Class="Portal.Services.PayPal.IPNListener" %>
IPNListener.ashx.cs
//-----------------------------------------------------------------------------
// <copyright file="IPNListener.cs" company="DCOM Productions">
// Copyright (c) DCOM Productions. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Web;
using Portal.PayPal;
namespace Portal.Services.PayPal
{
/// <summary>
/// Summary description for IPNListener
/// </summary>
public class IPNListener : IHttpHandler
{
/// <summary>
/// Receives the HttpWebRequest via an HttpContext and processes the request
/// </summary>
public void ProcessRequest(HttpContext context) {
// I gutted this, because it still produces the same error
context.Response.Write("Hello World!");
}
/// <summary>
/// Gets a System.Boolean value that indicates whether the generic handler may be reused
/// </summary>
public bool IsReusable {
get {
return false;
}
}
}
}
When I attempt to navigate to the handler, I receive the following error.
Parser Error
Description: An error occurred during the parsing of a resource required to service
this request. Please review the following specific parse error details
and modify your source file appropriately.
Source Error
Line 1: <%@ WebHandler Language="C#"
CodeBehind="IPNListener.ashx.cs"
Class="Portal.Services.PayPal.IPNListener" %>
Source File: /portal/services/paypal/ipnlistener.ashx Line: 1
Here is what I have done so far:
(1) Gutted the Handler. I gutted it to a simple Hello World
handler as seen in the code I posted to eliminate the possibility of an error in my code. The handler was previously working just fine, and I'm actually not sure what has caused it to stop working.
(2) Checked Version Control. Like I said previously, the handler was working fine a day or so ago. I checked version control for the file's history to see if anything had changed, and it has not.
(3) Application Pool. I checked the application pool in IIS 7, and it is running ASP.NET v4.0
as it should be.
(4) Verified Build Actions. I verified that IPNListener.ashx
's build action is set to Content
, and that IPNListener.ashx.cs
's build action is set to Compile
.
(5) Verified DLL Integrity. I verified using IL Disassembler that the type Portal.Services.PayPal.IPNListener
does exist in the compiled DLL file.
(6) Virtual Application Directory. The folder /Services/PayPal
is not a virtual application, and I've never had to make it one for a Generic Handler to work, but I tried it anyway and the same error is still produced.
(7) Clean Rebuild. I have tried cleaning the solution, then rebuilding. There are no compiler errors. Then proceed to publish the web application, everything is fine.
(8) Checked Dependencies. I checked to make sure all required files, and dependencies are deployed. Everything checks out.
I really have no clue as to why this stopped working. Everything was tested and ready to go to publish everything live today for my first software product, and when I did one last test run on the payment services it was returning a 500 Internal Server Error, in which further investigation showed that it is being caused by this problem.
I'm actually really stumped. I searched through all other posts regarding ASHX handlers and this issue here on StackOverflow, as well as all over the web and found nothing useful to my specific issue here.
It might be something really simple I am overlooking, but I can't seem to put my finger on it.
(Update) 5/29/2012 10:57 PM. Going off of Ray Cheng
's comment and mine, I realized that the service used to live in /PayPal/IPNListener.ashx
, and was moved to /Services/PayPal/IPNListner.ashx
. When the move was done, all the namespaces, and class locations were updated in the ASHX file.
Out of curiosity, I copied the handler to /PayPal/IPNListener.ashx
, updated the namespaces and classes in the ASHX files, and navigated to the location, and the service works fine.
Essentially
/Services/PayPal/IPNListener.ashx
produces a 500 Internal Server Error due to Could not create type
, and
/PayPal/IPNListener.ashx
works just fine. So why does having the handler one folder hierarchy up make a difference in working?
The problem was something simple. I have two IIS 7 servers, one for local testing, and the other live on the internet.
The local IIS server had the parent directory /Services
set as an virtual application. I found that having a virtual application somewhere in the path to the generic handler causes the ASP engine to fail to create the handler type. This explains why moving the service from /PayPal/IPNHandler.ashx
to /Services/PayPal/IPNHandler.ashx
broke, because the former path was not a virtual application, and the latter was, breaking the handler.
Removing the virtual application for /Services
resolved the problem on the test server, and it now works as expected.
There wasn't supposed to be a virtual application in that path anyway, but it was an oversight because /Services
is used for more than just this handler.
The problem on the live server, turns out, was an service address to a WCF Service that is used in the handler was pointing to the test server using the localhost
alias, thus being an invalid address. The live server did not have any problems with virtual application configuration or anything, it was an incorrect address.
Updating the incorrect address resolved the 500 Internal Server error. This is irrelevant as to the original issue of the handler causing a parse error, but was the second issue found and resolved before being able to have everything work.