title: HttpException Request is not available in this context
body: <p>I am trying to get the <code>id</code> from a URL but I am getting this error:</p>
  
  <p><a href="https://i.stack.imgur.com/YjZwD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YjZwD.jpg" alt="enter image description here"></a></p>
  
  <p>This is my code:</p>
  
  <pre><code>private int get_id()
      {
          if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
          {
              int id = Convert.ToInt32(Request.QueryString["id"]);
              return id;
          }
          else
          {
              int def_id = 1;
              return def_id;
          }
      }
  
      [WebMethod]
      public static List&lt;Product&gt; get_product()
      {
          product_detail get = new product_detail();
          ProductModel db = new ProductModel();
          //List&lt;Product&gt; product = new List&lt;Product&gt;();
          int id = get.get_id();
          List&lt;Product&gt; product = db.get_product(id);
          return product;
  
  
      }
  
  
  }
  </code></pre>
  
  <p>But when I run it, I get this error and can't get the <code>id</code> of this url: <a href="http://localhost:31621/product_detail.aspx?id=2" rel="nofollow noreferrer">http://localhost:31621/product_detail.aspx?id=2</a></p>