When using Couchbase as Session State Provider, Session_onStart does not get hit upon first session start, why?

When hitting debug and the application is starting up, Session_OnStart() will not get hit when the default browser goes to the web.

When waiting for the application to startup and then deleting all cookies and hitting refresh - (OR using other browsers) - then Session_OnStart() gets called again as usual.

Session_OnStart() always get hit when using the default InProc state provider.

Code:

		protected void Session_OnStart()
		{
			Session["SessionStart"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
			Session["RemoteHost"] = Request.ServerVariables["REMOTE_HOST"];
		}

Web.Config

	<sessionState customProvider="Couchbase" mode="Custom">
	  <providers>
		<add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" />
	  </providers>
	</sessionState>

Why?

2 Answers

« Back to question.

Hi,

I just created a new MVC 4 application with the "Basic" template. After that I installed the NuGet package for the Couchbase provider and added configuration according to this blog post: http://blog.couchbase.com/introducing-couchbase-aspnet-sessionstate-prov...

In my Global.asax i added the following:

protected void Session_Start(object sender, EventArgs e)
{
    Session["Test"] = DateTime.Now;
}

then I added a simple HomeController with the following "Index" action:

public ActionResult Index()
{
    return new ContentResult {Content = Session["Test"].ToString()};
}

Works. To get the session to be renewed, I had to go in and delete the session documents in the bucket.

You can also test this by adding e.g. this action to the HomeController:

public ActionResult Kill()
{
    Session.Abandon();
    return RedirectToAction("Index");
}

Cheers,

//Daniel

« Back to question.

I am getting the exact same errors as rille111 in his response. It is random.

A little more information:

When testing locally with couchbase on my local machine this does not happen. It only happens on the production server.

Also if I switch to using the enyim memcached-providers on production going against the couchbase server (default bucket) it also works fine.

Any ideas?

Thanks.