I'm evaluating Padarn for my project and I'm trying to implement a very simple authentication scheme:
namespace SampleSite
{
public class Login : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["login"] == "admin" && Request.Form["password"] == "123")
{
Session["username"] = "admin";
Response.Redirect("PostFiles.html");
}
else
{
Response.Redirect("Default.aspx");
}
}
}
}
It's working fine for a single user, however, when my friend tried to hit the page while I was debugging, a NullReferenceException was thrown at
Session["username"] = "admin";
Then we realized it's not working for concurrent users.
Are concurrent sessions really not supported? Is this some configuration I'm missing?
It turns out that, for no good reason at all, the hands-on lab ships with a domain set for the cookies. Even worse, the domain is nonsensical. It's probably a remnant of some sort of testing we were doing internally and never reverted for release.
What's happening is that the configuration has this in it:
This is causing the session cookies to get stripped from any client (unless it's IP happens to be 169.0.0.2).
This, in turn, causes a new session to be generated with every browser request, which effectively throws out your session variables.
Change your web.config to not have a cookie domain like this, and all will be well:
The
NullReferenceException
you get in yourPage
code is because theSession
object on the page innull
. This happens when the maximum number of Sessions for the service has been reached (which occurs quickly when each request is generating a new Session).