[英]jquery to asp.net c# generic handler
I'm trying to call ac# generic handler from a jquery.ajax call. 我正在尝试从jquery.ajax调用中调用ac#通用处理程序。
My site structure is: a/handlers/dowork.ashx calling.aspx 我的网站结构是:a / handlers / dowork.ashx call.aspx
here is the code for the above files: calling.aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="calling.aspx.cs" Inherits="myapp.calling" %> 这是上述文件的代码:calling.aspx文件<%@页面语言=“ C#” AutoEventWireup =“ true” CodeBehind =“ calling.aspx.cs” Inherits =“ myapp.calling”%>
//the jsonDataObj looks like: 1,t
function sendData(jsonDataObj) {
var status = "";
jQuery.ajax({
type: "POST",
url: '/a/handlers/dowork.ashx/doit',
data: jsonDataObj,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (output, status, xhr) {
status = xhr.responseText;
statusCode = xhr.status;
console.log(status + " " + statusCode);
},
error: function (xhr, textStatus, errorThrown) {
status = "{'d':'0," + errorThrown + "'}";
status = status.replace(/'/g, '"');
statusCode = xhr.status;
console.log(status + " " + statusCode);
}
});
}
dowork.ashx.cs -- generic handler dowork.ashx.cs-通用处理程序
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Text;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Elmah;
namespace myapp
{
public class dowork : System.Web.UI.Page, IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
}
public bool IsReusable
{
get { return false; }
}
[System.Web.Services.WebMethod()]
public static string doit(object data)
{
string status = string.Empty;
string number = string.Empty;
string letter = string.Empty;
dynamic strings = ((IEnumerable)data).Cast<object>().Select(x => x == null ? x : x.ToString()).ToArray();
number = strings(0).ToString();
letter = strings(1).ToString();
status = number + letter;
return status;
}
}
}
My Error is as follows: 我的错误如下:
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 'myapp.a.handlers.dowork'.
Source Error:
Line 1: <%@ WebHandler Language="C#" CodeBehind="dowork.ashx.cs" Class="myapp.a.handlers.dowork" %>
Source File: /a/handlers/dowork.ashx Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1038.0
I can't seem to figure this one out. 我似乎无法弄清楚这一点。 Any suggestions? 有什么建议么?
From this line of error i am seeing that 从这一行错误中,我看到了
Line 1: <%@ WebHandler Language="C#" CodeBehind="dowork.ashx.cs" Class="myapp.a.handlers.dowork" %>
the fully qualified class name is myapp.a.handlers.dowork
完全合格的类名称为myapp.a.handlers.dowork
but in your dowork.ashx.cs
file the fully qualified class name will be myapp.dowork
但在dowork.ashx.cs
文件中,完全限定的类名称为myapp.dowork
So give a try giving the proper class name in dowork.ashx.cs
file. 因此,请尝试在dowork.ashx.cs
文件中提供适当的类名称。
it should solve the issue 它应该解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.