Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:55:03+00:00 2026-06-05T22:55:03+00:00

EDIT: Simple version of the question: I want to create server variables in the

  • 0

EDIT:

Simple version of the question:
I want to create server variables in the .NET httpmodule and read them in my classic ASP code.

Is this possible? or the wrong approach?

ENDEDIT:

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.

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.

Do I have the wrong approach?

       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);

Which seems to set them correctly; however, when I try to read them from my classic asp page they do not appear…

CLASSIC ASP:

<html>
<%
  for each x in Request.ServerVariables
        response.write("<h2>"& x & "</h2>")
  next
%>
<h2>hello!</h2>
</html>

ASP.NET ASPX Page where they do appear:

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<% 
    foreach (var x in Request.ServerVariables)
   {
     %>
     <div>
     <%= x.ToString() %>
     </div>
     <%
   }
        %>    
    </div>
    </form>
</body>
</html>

full http module:

namespace PlatoModules 
{
    public class PlatoModule : IHttpModule
    {

        public void Init(HttpApplication context)
        {
            context.BeginRequest += (s, e) => BeginRequest(s, e);
            context.EndRequest += (s, e) => 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("<h1><font color=red>" +
                              "HelloWorldModule: Beginning of Request" +
                              "</font></h1><hr>");
                      }*/

                BlackMagicSetServerVariables(application);
                if (fileExtension.Equals(".asp"))
                {
                    string content = @"<h1><font color=red>" +
                        "BeginReq" +
                        @"</font></h1><br>";
                    context.Response.Write(content);
                    context.Response.Flush();
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(@"<h1><font color=red>" +
                        "error" + ex.Message +
                        @"</font></h1><br>");
            }
        }


        private void EndRequest(Object source, EventArgs e)
        {

            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;
            context.Response.Write(@"<br><h1><font color=red>" +
                  @"Enter endreq </font></h1>");
            string filePath = context.Request.FilePath;
            string fileExtension =
                VirtualPathUtility.GetExtension(filePath);
            if (fileExtension.Equals(".asp"))
            {
                context.Response.Write(@"<br><h1><font color=red>" +
                    @"EndReq </font></h1>");
            }
            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);

        }

    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:55:04+00:00Added an answer on June 5, 2026 at 10:55 pm

    Solution …

    Tentatively –

    I cannot modify server variables and have them be ‘picked up’ by the classic asp code on the request; however I could get this code add in headers, so I’m going to use headers. If this is an awful way to be doing things please let me know in the comments! Thanks for helping me out Frank!

    SO here’s the code:

    CLASSIC ASP:

    <%
    
    
    for each x in Request.ServerVariables
      Response.Write("<h2>"& x  & ":" & Request.ServerVariables(x) & "</h2>") 
    next
    
     Response.Write("<h2> DAVE: " & Request.ServerVariables("HTTP_DAVE") & "</h2>")
     Response.Flush()
    %>
    <h2>hello!</h2>
    </html>
    

    HTTPMODULE:

    namespace PlatoModules
    {
        public class PlatoModule : IHttpModule
        {
    
            public void Init(HttpApplication context)
            {
                context.BeginRequest += (s, e) => BeginRequest(s, e);
                context.EndRequest += (s, e) => EndRequest(s, e);
            }
    
            public String ModuleName
            {
                get { return "test"; }
            }
    
            public void Dispose()
            {
            }
    
            // Your BeginRequest event handler.
            private void BeginRequest(Object source, EventArgs e)
            {
                Debugger.Launch();
                HttpApplication application = (HttpApplication)source;
    
                HttpContext context = application.Context;
                try
                {
    
                    context.Response.Write(
                        "<h1><font color=red>HelloWorldModule: Beginning of Request</font></h1><hr>");
    
                    context.Request.Headers.Add("DAVE", "DAVOLIO");
                    context.Response.Flush();
                }
                catch (Exception ex)
                {
                    context.Response.Write(
                        ex.Message);
                }
            }
    
    
            private void EndRequest(object source, EventArgs e)
            {
                HttpApplication application = (HttpApplication)source;
                HttpContext context = application.Context;
                var content = @"<hr><h1><font color=red>HelloWorldModule: End of Request</font></h1>";
                context.Response.Write(content);
                context.Response.Flush();
            }
    
    
        }
    
    
    }
    

    Relevent web.config

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"> 
            <add name="PlatoModule" type="PlatoModules.PlatoModule" /> 
            </modules>
    ...
        </system.webserver>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Play with it here: http://jsbin.com/ocicu4/4/edit Simple Accordion, I only want one section open at
I have a simple in-line edit in my grid, and I want to commit
If you create a simple button and then choose Edit Template -> Edit a
This seems like such a simple question. I have several Edit boxes on my
Pretty simple question: which one of these two PHP (version 5+) header call is
I want to create a simple graphical user interface to allow non-technical users to
Very simple question but all the answer I read over the web doesn't apply.
When you edit a simple page in the design view, you can add an
I created a simple detail edit form earlier, and decided to data bind some
Is there a simple way to reformat my HTML from within Komodo Edit or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.