Search code examples
asp.netjquerygeneric-handler

Generic Handler Jquery Post error


I am getting this error (at the bottom) when I try to run this code using a generic handler

Jquery Code

 $.post("CheckUserName.ashx?username=Aaron902", 
                    function (result) { 
                        $('#username_availability_result').html('Name already exist!'); 

                        if (result == "exists") { 
                            $('#username_availability_result').html('Name already exist!'); 
                        } 
                        else { 
                            $('#username_availability_result').html('Still available'); 
                        } 

                    }); 

Handler Code

 public void ProcessRequest(HttpContext context) 
        { 
            string user_name = context.Request.QueryString["username"]; 
            string output = "here"; 
            output = CheckUserNameAvailability(user_name); 
            context.Response.Write(output); 
            context.Response.End(); 

        } 

Server Error in '/' Application.

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.

Parser Error Message: Could not create type 'Dating.CheckUserName'.

Source Error: Line 1: <%@ WebHandler Language="C#" CodeBehind="CheckUserName.ashx.cs" class="Dating.CheckUserName" %>

Source File: /CheckUserName.ashx Line: 1


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237


Solution

  • I found a fix to my issue although I am not sure why it works this way and not the original way. All I did was remove the code behind file and put all the code that was there into the ashx file instead of having it in the ashx.cs file.

    Of course I removed the directive CodeBehind="CheckUserName.ashx.cs"