Last active
July 21, 2019 18:54
-
-
Save tpokorra/52bdfbf3472e3f214bdac90ab16b2543 to your computer and use it in GitHub Desktop.
Testing Sessions with aspx on Mono
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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