/// <summary> /// Register the given citizen in the current Mega-City One session. /// </summary> /// <param name="context">The HttpContext of the current request</param> /// <param name="citizen">The Mega-City One citizen</param> public static void Login(HttpContextBase context, McoCitizen citizen) { if (context == null) { throw new ArgumentNullException("context"); } if (citizen == null) { throw new ArgumentNullException("user"); } Login(context.ApplicationInstance.Context, citizen); }
/// <summary> /// Register the given citizen in the current Mega-City One session. /// </summary> /// <param name="context">The HttpContext of the current request</param> /// <param name="citizen">The Mega-City One citizen</param> public static void Login(HttpContext context, McoCitizen citizen) { if (context == null) { throw new ArgumentNullException("context"); } if (citizen == null) { throw new ArgumentNullException("user"); } Logoff(context); // Cleanse the context before proceeding string securitySessionId = Guid.NewGuid().ToString(); DateTime expiration = DateTime.Now.AddDays(1); string domain = context.Request.Url.Host; if (context.Request.UrlReferrer != null) { domain = context.Request.UrlReferrer.Host; } context.Response.Cookies.Set(new HttpCookie("mco", securitySessionId) { Expires = expiration, HttpOnly = true, Path = "/" }); string userHostAddress = GetUSerHostAddress(context.Request); citizen.Data["UserHostAddress"] = userHostAddress; MemoryCache.Default.Add(securitySessionId, citizen, new DateTimeOffset(expiration)); LogManager.GetLogger("MegaCityOne.Mvc.McoSession").Info( string.Format("User session started for '{0}' from [{1}].", citizen.Name, userHostAddress)); context.User = citizen.Principal; }