Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net中访问.ashx文件时出错_C#_Asp.net_Ashx_Ihttphandler - Fatal编程技术网

C# 在asp.net中访问.ashx文件时出错

C# 在asp.net中访问.ashx文件时出错,c#,asp.net,ashx,ihttphandler,C#,Asp.net,Ashx,Ihttphandler,目标: 通过复制现有和正在使用的product.ashx并重命名为client.ashx创建client.ashx 修改了client.ashx以处理与product.ashx类似的逻辑 我这样做是因为我不知道如何在VisualStudio社区从头开始创建.ashx。在添加/新建项之后,我没有看到.ashx的文件选项 目标是使用client.ashx上传客户端图像。 文件product.ashx上载产品图像 我对product.ashx的jscript调用与往常一样工作,尽管当我调用新的clie

目标: 通过复制现有和正在使用的product.ashx并重命名为client.ashx创建client.ashx 修改了client.ashx以处理与product.ashx类似的逻辑

我这样做是因为我不知道如何在VisualStudio社区从头开始创建.ashx。在添加/新建项之后,我没有看到.ashx的文件选项

目标是使用client.ashx上传客户端图像。 文件product.ashx上载产品图像

我对product.ashx的jscript调用与往常一样工作,尽管当我调用新的client.ashx时,它似乎调用product.ashx而不是client.ashx

 $.ajax({
        type: "POST",
        url: "/handlers/client.ashx",
        data: formData,
        global: false,
        success: function (result) {

            var response = JSON.parse(result);
            var success = response.Success;

            if (success) {
                window.location.replace(window.location);
            }
            else {
                ChangeStatusMessage(response.Message, false, true);
            }
        },
        processData: false,
        contentType: false,
        error: function (result) {
            ChangeStatusMessage("An unknown error occurred while trying to upload the image.  Please reload the page and try again", false, true);
        }
    });
调用client.ashx的示例

 $.ajax({
        type: "POST",
        url: "/handlers/client.ashx",
        data: formData,
        global: false,
        success: function (result) {

            var response = JSON.parse(result);
            var success = response.Success;

            if (success) {
                window.location.replace(window.location);
            }
            else {
                ChangeStatusMessage(response.Message, false, true);
            }
        },
        processData: false,
        contentType: false,
        error: function (result) {
            ChangeStatusMessage("An unknown error occurred while trying to upload the image.  Please reload the page and try again", false, true);
        }
    });

这是一个常见的错误。您可能忘记更改新文件中的代码隐藏引用(它可能指向旧的.cs文件)顺便说一句:Visual Studio确实有一个新的.ashx文件模板,它在“new”、“file”中称为“Generic Handler”。如果您单独调用它的run?(仅在url中)在visual studio中,您在asp.net handlerNo下创建此文件,代码隐藏是相同的文件名。