Skip to content

Instantly share code, notes, and snippets.

@tpokorra tpokorra/session.aspx
Last active Jul 21, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.