title: What is the equivalent of a Servlet (Java class that extends HttpServlet in tomcat) in an ASP.net project?
body: <p>I started programming my own web applications during the beginning of the Apache Tomcat project, and thus when I am writing a Servlet that responds with some small piece of JSON to some GET or POST my code would look something close to this:</p>
  
  <pre><code>package com.stackoverflow.question;
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.*;
  import org.json.*;
  
  public class SimpleServlet_json extends HttpServlet {
    private static final long serialVersionUID = 1L;
  
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
      request.setCharacterEncoding("UTF-8");
      JSONObject json = new JSONObject();
      try {
        json.put("Success", true);
        json.put("Name", request.getParameter("name"));
      } catch (JSONException e) {}
      response.setContentType("application/json");
      response.getOutputStream().print(json.toString());
    }
  }
  </code></pre>
  
  <p>My question is <strong>"what is the equivalent method/design/New Item for ASP.net?"</strong></p>
  
  <p>I have been writing these as WebForms that look like this:</p>
  
  <p>First the (basically empty) <code>.aspx</code> file:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SimpleServlet_json.aspx.cs" Inherits="com.stackoverflow.question.SimpleServlet_json" %&gt;
  </code></pre>
  
  <p>Then this <code>.cs</code> file:</p>
  
  <pre><code>namespace com.stackoverflow.question
  {
    public partial class SimpleServlet_json : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        var json = new JSONResponse()
        {
          Success = Request.QueryString["name"] != null,
          Name = Request.QueryString["name"]
        };
        Response.ContentType = "application/json";
        Response.Write(JsonConvert.SerializeObject(json));
      }
    }
    [Serializable]
    class JSONResponse
    {
      public string Name { get; set; }
      public bool Success  { get; set; }
    }
  }
  </code></pre>
  
  <p>But I secretly worry that I am asking my fellow c# programmers to adopt a non-intuitive style.</p>
  
  <p>These examples are rather contrived, in practice they are used as the JSON representation of a database entity.  For an example the URL <code>example.com/product/1</code> is the HTML version (with a JSP or ASPx page associated with the URL) while <code>example.com/product/1.json</code> is the JSON representation (with one of these classes).  I'm a fan of URL Rewriting.</p>