How To Get All Features in FeatureClass with ArcObjects

Share a Session Across ASP Classic and ASP.NET Webforms

24. November 2016 04:56 by Scott in C#, ASP Classic, Webforms  //  Tags:   //   Comments (0)

This is a brief code piece how to share sessions across ASP Classic and ASP.NET.  Having to make some changes on a classic site and I would rather not keep writing classic.  So after I migrated the site to ASP.NET using DLRSOFT.ASP, I needed to make sure that I can access the ASP Classic Session without replacing destroying the ASP Classic code base.  So I got this gem from Jonavis but I have made a few updates to it to make it work better.

This is a page called aspsession.asp.  This page allows me to send and receive ASP Classic session variables.

<%@ Language=VBScript %>
<%Option Explicit%>
<%Response.Expires=-1%>

<%
Dim strMode, strName, strValue

If Request.ServerVariables("REMOTE_ADDR") = Request.ServerVariables("LOCAL_ADDR") Then
    strMode = Request.QueryString("mode")
    strName = Request.QueryString("name")
    If strMode = "get" Then
        Response.Write(Session(strName))
    ElseIf strMode = "set" Then
        strValue = Request.QueryString("value")
        Session(strName) = strValue
    End If
End If
%>
 
 
 
Then this is the C# logic I plugged in so that I can send and receive the session from ASP Classic.
 
 public static object Get(string name)
        {
            HttpContext context = HttpContext.Current;
            object value = null;
            String[] cookies = context.Request.Cookies.AllKeys;
            System.Uri uri = context.Request.Url;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Scheme + "://" + uri.Host + ":" + uri.Port.ToString() + "/Services/AspSession.asp?mode=get&name=" + name);

            for (int i = 0; i < cookies.Length; i++)
            {
                HttpCookie cookie = context.Request.Cookies[cookies[i]];
                if (cookie.Name.StartsWith("ASPSESSION"))
                {
                    request.Headers.Add("Cookie: " + cookie.Name + "=" + cookie.Value);
                }
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            StreamReader readStream = new StreamReader(responseStream, encode);
            value = readStream.ReadToEnd();
            response.Close();
            readStream.Close();

            return value;
        }

        public static void Set(string name, object value)
        {
            HttpContext context = HttpContext.Current;

            String[] cookies = context.Request.Cookies.AllKeys;

            System.Uri uri = context.Request.Url;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Scheme + "://" + uri.Host + ":" + uri.Port.ToString() + "/Services/aspsession.asp?mode=set&name=" + context.Server.UrlEncode(name) + "&value=" + context.Server.UrlEncode(value.ToString()));

            for (int i = 0; i < cookies.Length; i++)
            {
                HttpCookie cookie = context.Request.Cookies[cookies[i]];

                if (cookie.Name.StartsWith("ASPSESSION"))
                {
                    request.Headers.Add("Cookie: " + cookie.Name + "=" + cookie.Value);
                }
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();

        }
 
After that, this method simply works.