Skip to content

Instantly share code, notes, and snippets.

@tpokorra
Last active July 21, 2019 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpokorra/52bdfbf3472e3f214bdac90ab16b2543 to your computer and use it in GitHub Desktop.
Save tpokorra/52bdfbf3472e3f214bdac90ab16b2543 to your computer and use it in GitHub Desktop.
Testing Sessions with aspx on Mono
<%@ Page Language="C#" src="session.aspx.cs" %>
<html xmlns="www.w3.org/1999/xhtml">
<%@ Import Namespace="System.Threading" %>
<head runat="server">
<title></title>
</head>
<body>
<div>
<%
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/>");
}
else
{
Session["browser"] = Request.UserAgent + " " + DateTime.Now.ToString();
Test.Test.Set(Session["browser"].ToString());
}
Response.Write("Thread ID: " + Thread.CurrentThread.ManagedThreadId);
%>
</div>
</body>
</html>
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