Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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 |通过ajax发送的值在处理程序中作为null接收_C#_Asp.net - Fatal编程技术网

C# asp.net |通过ajax发送的值在处理程序中作为null接收

C# asp.net |通过ajax发送的值在处理程序中作为null接收,c#,asp.net,C#,Asp.net,我正在尝试将“文件”附件发送给handler(并通过电子邮件发送) 这是我用来将其发送给handler(JS)的代码 当我调试它时,我会看到正确的值,包括文件(在java脚本中调试) 如何在处理程序页面中获取它们 这样我就得到了空值,为什么 public void ProcessRequest(HttpContext context) { string fullName = context.Request.Form.Get("fullName"); //It's Null

我正在尝试将“文件”附件发送给handler(并通过电子邮件发送)

这是我用来将其发送给handler(JS)的代码

当我调试它时,我会看到正确的值,包括文件(在java脚本中调试)

如何在处理程序页面中获取它们

这样我就得到了空值,为什么

public void ProcessRequest(HttpContext context)
{      
    string fullName = context.Request.Form.Get("fullName"); //It's Null
    string email = context.Request.Form.Get("email");//It's Null
    string chkBox_ad = context.Request.Form.Get("checkBox");  //It's Null
    /////how can i get the file here ??

    bool mailSent = Mail.SendCV(fullName, email, chkBox_ad);
    context.Response.ContentType = "text/plain";

    if (mailSent)
    {
        context.Response.Write("true");
    }
    else
    {
        context.Response.Write("false");
    }
}
这可能有用

var postedFile = context.Request.Files[0];

MultipartParser是一个开源类-请参见

谢谢,但它只是部分回答了我的问题。正如我所写的,如果我在handler.ashx中设置一个断点,它就永远不会命中。原因是什么?哦,对不起。如何将url(Handlers/SendCV.ashx)映射到handler(handler.ashx)?您正在使用web配置的system.web.urlMappings元素吗?没关系:)这就是我映射-“Handlers/SendCV.ashx”的方式,若我更改了“contentType”和“processData”,它就可以工作了。那个么,我如何将文件发送到“handler”?让我更准确地说,我实际上在handler.ashx中得到了所有值,但我得到的值都是null-我更新了我的问题。
var postedFile = context.Request.Files[0];
var parser = new MultipartParser(context.Request.InputStream);
if (parser.Success) {
  byte[] content = parser.FileContents;
  string filename = parser.Filename;
}