Friday, September 2, 2011

Fix for Loveseat CouchDB Login Session Issue

There is a bug in CouchDB (love seat) regarding maintaining user session..

In CouchBase.cs class the method GetSession is not returning the value it has created in cookie. it is simply returning "cookie" from that method... which is always null.. it leads to user expiry immediatly after login though that use session is ready in cookie...

delete that method from you couchbase and use the following method

protected Cookie GetSession()
{
var cookie = cookiestore["authcookie"];

if (cookie != null)
return cookie;

if (string.IsNullOrEmpty(username)) return null;
var request = new CouchRequest(baseUri + "_session");
var response = request.Post()
.ContentType("application/x-www-form-urlencoded")
.Data("name=" + username + "&password=" + password)
.GetResponse();

var header = response.Headers.Get("Set-Cookie");
if (header != null)
{
var parts = header.Split(';')[0].Split('=');
var authCookie = new Cookie(parts[0], parts[1]);
authCookie.Domain = response.Server;
cookiestore.Add("authcookie", authCookie, TimeSpan.FromMinutes(9));
}
return cookiestore["authcookie"];
}

No comments:

Post a Comment