Skip to content

Instantly share code, notes, and snippets.



Last active Jul 21, 2019
What would you like to do?
Testing Sessions with aspx on Mono
<%@ Page Language="C#" src="session.aspx.cs" %>
<html xmlns="">
<%@ Import Namespace="System.Threading" %>
<head runat="server">
Response.Write( "Hello World<br/>");
Response.Write("<a href='?action=get'>Test me: Get</a><br/>");
Response.Write("<a href='?action=set'>Test me: Set</a><br/>");
if (Request["action"] == "get")
Response.Write( Session["browser"] + "<br/>");
Response.Write( Test.Test.Get() + "<br/>");
Session["browser"] = Request.UserAgent + " " + DateTime.Now.ToString();
Response.Write("Thread ID: " + Thread.CurrentThread.ManagedThreadId);
using System;
namespace Test
public class Test
// Static variables are stored in the thread, and threads are reused for different sessions
static string StaticTest;
public static void Set(string s)
StaticTest = s;
public static string Get()
if (StaticTest == String.Empty) return "Empty";
return StaticTest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.