My WebHandler showing error and i dont know if its from my web.config file
This is the code
public class Search_CS : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT UserName,ImageName FROM User3 WHERE UserName like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
StringBuilder sb = new StringBuilder();
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(string.Format("{0}-{1}.jpg{2}", sdr["UserName"], sdr["ImageName"], Environment.NewLine));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
WEB.CONFIG
<urlMappings enabled="true">
<add url="~/Home.aspx" mappedUrl=" ~/Search_CS.ashx"/>
</urlMappings>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.5" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.5" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.5" />
</handlers>
ERROR
Server Error in '/' Application.
The parameterized query '(@SearchText nvarchar(4000))SELECT UserName,ImageName FROM User3' expects the parameter '@SearchText', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The parameterized query '(@SearchText nvarchar(4000))SELECT UserName,ImageName FROM User3' expects the parameter '@SearchText', which was not supplied.
Source Error:
Line 22: StringBuilder sb = new StringBuilder();
Line 23: conn.Open();
Line 24: using (SqlDataReader sdr = cmd.ExecuteReader())
Line 25: {
Line 26: while (sdr.Read())