I have a generic handler that I intend to use to accept an HTTP POST from Sage Pay. I am giving them the url for the POST however it is giving an error 500 (internal server error) which I guess is something wrong on my end. If I want the generic handler to accept this POST and reply with a response is there anything special that I need to do?
I noticed in my web.config under the tags there is only a reference to a .asmx file. Do I need to add anything here?
My web.config section looks like this:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
My generic handler code looks like this. There are other clauses in there to make sure something is returned no matter what Sage send just to test that the handler is working. It seems not:
public class SagePayHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
string status = context.Request.Params["Status"];
string statusDetail = context.Request.Params["StatusDetail"];
switch (status.ToUpper())
{
case "OK":
{
StringBuilder content = new StringBuilder();
content.Append("Status=" + HttpUtility.UrlEncode("OK"));
content.Append("&RedirectURL=" + HttpUtility.UrlEncode("http://fooIp:80/Success.aspx?Code=SUCCESS"));
content.Append("&StatusDetail=" + HttpUtility.UrlEncode("OK"));
//SAGE TEST
context.Response.ContentType = "application/x-www-form-urlencoded"; ;
context.Response.ContentEncoding = System.Text.Encoding.Default;
context.Response.Write(content.ToString());
break;
}
}
}
}