title: How to use a piece of code to handle all Http requests on Asp.net core
body: <p>I want to customize the request processing flow myself. I don't want to use the Controller under Asp.net core to process the request. But there is a premise that there must be a class method or a delegate (containing Request and response formal parameters), where all requests are processed</p>
  
  <p>For response processing, I hope to use Asp.net core's default response processing method (if it can be done), such as Ajax requests, dynamic page output, response pictures, file downloads, etc.</p>
  
  <p>Envisioned code：</p>
  
  <pre><code>var handler=HTTP.handler((req, res) =&gt; {
    if(req.getHeader("x-requested-with")){
        if(req.para("username")==null){
           res.endError(403)
        }else{
           res.statusCode = 200;
           res.setHeader('Content-Type', 'text/plain');
           res.end('Hello World');
        }
  
    }else{
          res.view('/test/index.cshtml');
    }
  
  });
  </code></pre>