title: Custom System.Web.HttpContext for .Net Standard
body: <p>We have several websites that are written in .Net Framework.
  Now we want to move to .Net Core.
  We want to do it one by one so the old websites and the new ones should live side by side.
  All websites share common dlls, for example LoggerDll.</p>
  
  <p>In order to use only one dll for both websites (old and new) we change LoggerDll to .Net Standard and add reference to it from both websites.</p>
  
  <p>The problem is that LoggerDll has reference to System.Web dll in order to get the IP of the request (and other request information) for writing to log, and it's not exist in .Net Core.</p>
  
  <p>For example:</p>
  
  <pre><code>public void WriteToLog(string message)
  {
      //This line doesn't compile in .Net Core
      string userIp = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
      WriteToDB(message, userIp);
  }
  </code></pre>
  
  <p>I don't want to pass the IP as parameter to WriteToLog because then I'll need to add it as parameter in ALL the methods that call it, and almost every method calls to WriteToLog when exception happen.</p>
  
  <p>So I prefer to keep getting the request information from some "global" object, but it should compile in .Net Core and .Net Framework.</p>
  
  <p>I thought of creating new class, "MyRequestInfo", create a static property for it, and in the "BeginRequest" event fill it with the data.</p>
  
  <p>For example:</p>
  
  <pre><code>public class MyRequestInfo
  {
      public string UserIp { get; set; }
  }
  
  public class MyRequest
  {
      [ThreadStatic] \\ Is ThreadStatic is ok?
      public static MyRequestInfo ReqInfo { get; set; }
  }
  
  //Global.asax
  protected void Application_BeginRequest(object sender, EventArgs e)
  {
       MyRequest.ReqInfo.UserIp = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  }
  
  //LoggerDll
  public void WriteToLog(string message)
  {
      string userIp = MyRequest.ReqInfo.UserIp;
      WriteToDB(message, userIp);
  }
  </code></pre>
  
  <ol>
  <li>Is this soultion is OK?</li>
  <li>Is [ThreadStatic] is right or I should use AsynLocal or something else?</li>
  </ol>
  
  <p>Thank you</p>