public ActionResult Index() { var existingUser = ChatCookieHelperStub.GetDbUserFromCookie(this.Request); ChatViewModel chatViewModel = null; if (existingUser != null) { if (!ChatHub.IsUserRegisteredInDbUsersStub(existingUser)) { // cookie is invalid ChatCookieHelperStub.RemoveCookie(this.Response); return(this.RedirectToAction("Index")); } // in this case the authentication cookie is valid and we must render the chat chatViewModel = new ChatViewModel() { IsUserAuthenticated = true, UserId = existingUser.Id, UserName = existingUser.FullName, UserProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(existingUser.Email), GravatarHelper.Size.s32) }; } return(this.View(chatViewModel)); }
protected void Page_Load(object sender, EventArgs e) { var existingUser = ChatCookieHelperStub.GetDbUserFromCookie(new HttpRequestWrapper(this.Request)); if (existingUser != null) { if (!ChatHub.IsUserRegisteredInDbUsersStub(existingUser)) { // cookie is invalid ChatCookieHelperStub.RemoveCookie(new HttpResponseWrapper(this.Response)); // redirects the user to the same page this.Response.Redirect("/Home/Index.aspx"); } // in this case the authentication cookie is valid and we must render the chat IsUserAuthenticated = true; UserId = existingUser.Id; UserName = existingUser.FullName; UserProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(existingUser.Email), GravatarHelper.Size.s32); } }