title: Read server variables in classic ASP that have been set in ASP.NET httpmodule
body: <p>EDIT: </p>
  
  <p>Simple version of the question: 
  I want to create server variables in the .NET httpmodule and read them in my classic ASP code. </p>
  
  <p>Is this possible? or the wrong approach? </p>
  
  <p>ENDEDIT:</p>
  
  <p>So I have taken over a classic asp application and the author wrote an ISASPI Filter dll and he used it to set server variables for his classic asp applications.  I read on the IIS forums that the custom ISAPI filters are a bad idea and I should be using http modules if I'm going to move it forward. </p>
  
  <p>So I pulled this method off of the internet that lets me set the server variables in my httpmodule, which seems to work for adding the item to the server variable collection... however I can't read it from my classic asp code. </p>
  
  <p>Do I have the wrong approach? </p>
  
  <pre><code>       BindingFlags temp = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; 
  
          var context = app.Context;
  
          MethodInfo addStatic = null;
          MethodInfo makeReadOnly = null;
          MethodInfo makeReadWrite = null;
  
          Type type = app.Request.ServerVariables.GetType();
          MethodInfo[] methods = type.GetMethods(temp);
  
          foreach(var method in methods)
              {
                  switch( method.Name)
                  {
                      case "MakeReadWrite":
                          makeReadWrite = method;
                          break;
                      case "MakeReadOnly":
                          makeReadOnly = method;
                          break;
                      case "AddStatic":
                          addStatic = method;
                          break;
                  }
              }
  
          makeReadWrite.Invoke(context.Request.ServerVariables, null);
          string[] values = { "DaveVar", "hehehe" };
          addStatic.Invoke(context.Request.ServerVariables, values);
          makeReadOnly.Invoke(context.Request.ServerVariables, null);
  </code></pre>
  
  <p>Which seems to set them correctly; however, when I try to read them from my classic asp page they do not appear...</p>
  
  <p>CLASSIC ASP: </p>
  
  <pre><code>&lt;html&gt;
  &lt;%
    for each x in Request.ServerVariables
          response.write("&lt;h2&gt;"&amp; x &amp; "&lt;/h2&gt;")
    next
  %&gt;
  &lt;h2&gt;hello!&lt;/h2&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>ASP.NET ASPX Page where they do appear: </p>
  
  <pre><code>&lt;%@ Page Language="C#"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
  &lt;% 
      foreach (var x in Request.ServerVariables)
     {
       %&gt;
       &lt;div&gt;
       &lt;%= x.ToString() %&gt;
       &lt;/div&gt;
       &lt;%
     }
          %&gt;    
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>full http module: </p>
  
  <pre><code>namespace PlatoModules 
  {
      public class PlatoModule : IHttpModule
      {
  
          public void Init(HttpApplication context)
          {
              context.BeginRequest += (s, e) =&gt; BeginRequest(s, e);
              context.EndRequest += (s, e) =&gt; EndRequest(s, e); 
          }
  
          public String ModuleName
          {
              get { return "test"; }
          }
  
          public void Dispose()
          {
          }
  
          private void BeginRequest(Object source,
           EventArgs e)
          {
                 HttpApplication application = (HttpApplication)source;
                  HttpContext context = application.Context;
              try
              {
                  System.Diagnostics.Debugger.Launch();
                  // Create HttpApplication and HttpContext objects to access
                  // request and response properties.
                  string filePath = context.Request.FilePath;
                  string fileExtension =
                      VirtualPathUtility.GetExtension(filePath);
                  /*      if (fileExtension.Equals(".aspx"))
                        {
                            context.Response.Write("&lt;h1&gt;&lt;font color=red&gt;" +
                                "HelloWorldModule: Beginning of Request" +
                                "&lt;/font&gt;&lt;/h1&gt;&lt;hr&gt;");
                        }*/
  
                  BlackMagicSetServerVariables(application);
                  if (fileExtension.Equals(".asp"))
                  {
                      string content = @"&lt;h1&gt;&lt;font color=red&gt;" +
                          "BeginReq" +
                          @"&lt;/font&gt;&lt;/h1&gt;&lt;br&gt;";
                      context.Response.Write(content);
                      context.Response.Flush();
                  }
              }
              catch (Exception ex)
              {
                  context.Response.Write(@"&lt;h1&gt;&lt;font color=red&gt;" +
                          "error" + ex.Message +
                          @"&lt;/font&gt;&lt;/h1&gt;&lt;br&gt;");
              }
          }
  
  
          private void EndRequest(Object source, EventArgs e)
          {
  
              HttpApplication application = (HttpApplication)source;
              HttpContext context = application.Context;
              context.Response.Write(@"&lt;br&gt;&lt;h1&gt;&lt;font color=red&gt;" +
                    @"Enter endreq &lt;/font&gt;&lt;/h1&gt;");
              string filePath = context.Request.FilePath;
              string fileExtension =
                  VirtualPathUtility.GetExtension(filePath);
              if (fileExtension.Equals(".asp"))
              {
                  context.Response.Write(@"&lt;br&gt;&lt;h1&gt;&lt;font color=red&gt;" +
                      @"EndReq &lt;/font&gt;&lt;/h1&gt;");
              }
              context.Response.Flush();
          }
  
          void BlackMagicSetServerVariables(HttpApplication app)
          {
              BindingFlags temp = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; 
  
              var context = app.Context;
  
              MethodInfo addStatic = null;
              MethodInfo makeReadOnly = null;
              MethodInfo makeReadWrite = null;
  
              Type type = app.Request.ServerVariables.GetType();
              MethodInfo[] methods = type.GetMethods(temp);
  
              foreach(var method in methods)
                  {
                      switch( method.Name)
                      {
                          case "MakeReadWrite":
                              makeReadWrite = method;
                              break;
                          case "MakeReadOnly":
                              makeReadOnly = method;
                              break;
                          case "AddStatic":
                              addStatic = method;
                              break;
                      }
                  }
  
              makeReadWrite.Invoke(context.Request.ServerVariables, null);
              string[] values = { "DaveVar", "hehehe" };
              addStatic.Invoke(context.Request.ServerVariables, values);
              makeReadOnly.Invoke(context.Request.ServerVariables, null);
  
          }
  
      }
  
  
  }
  </code></pre>