Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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# HTTPResponse未到达客户端_C#_Http - Fatal编程技术网

C# HTTPResponse未到达客户端

C# HTTPResponse未到达客户端,c#,http,C#,Http,我有一个http处理程序,它已注册,工作正常。现在我想处理一个请求,并发送一个自定义html响应,然后在客户端上显示 因此,我的函数编写如下: public void ProcessRequest(HttpContext _context) { HttpResponse response = _context.Response; response.Clear(); var requestedUrl = _context.Request.Url; PhantomM

我有一个http处理程序,它已注册,工作正常。现在我想处理一个请求,并发送一个自定义html响应,然后在客户端上显示

因此,我的函数编写如下:

public void ProcessRequest(HttpContext _context)
{
    HttpResponse response = _context.Response;

    response.Clear();
    var requestedUrl = _context.Request.Url;
    PhantomModuleController pmc = new PhantomModuleController();
    response.BufferOutput = true;
    var snapshot = pmc.DoThings(requestedUrl); //this returns a string
    response.Write(snapshot); //i put it in the response
    response.ContentType = "text/html";
    response.End(); //it should send it to the client now
}
但据我的提琴手说,客户永远不会收到回复。事实上,httpresponse甚至从未发送过


我是否忘记了什么

,因为请求没有在Fiddler中显示为发送回客户端(也没有返回到客户端的错误),路由引擎可能会妨碍请求。场景由描述

但是,在其他情况下,您可能会请求文件 磁盘上不存在的。例如,如果您注册一个HTTP处理程序 直接指向实现IHttpHandler的类型。更不用说 浏览器自动生成的favicon.ico请求。ASP.NET 路由尝试将这些请求路由到控制器。一个解决方案 这是添加一个适当的忽略路由来指示该路由 我们应该忽略这些请求。不幸的是,我们无能为力 像这样:{*path}.aspx/{*pathinfo}

您需要设置路由引擎以忽略具有文件扩展名的路由。例如

routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});

http处理程序是接口或子类的事件处理程序或实现还是什么?MVC、webforms或其他哪种技术?可能与此问题中的相同:它是一个MVC应用程序,httphandler派生自IHttpHandler设置断点时,客户端调用是否到达处理程序?您是否已在
web.config
中注册了处理程序?我已注册它,它将到达处理程序