/// <summary> /// Checks if user has already logged in. /// if not, redirects back to login page with return url; /// if so, continue. /// </summary> public static void AuthenticateUserWithReturnUrl() { HttpContext context = HttpContext.Current; if (context.Session["UserId"] == null) { FormsAuthenticationHelper.SignOutAndRedirectToLoginWithReturnUrl(); } if (context.Session[Constant.SESSION_USERID] != null) { string connstring = Client.ConnectionString(HttpContext.Current.Session["clientid"].ToString()); SqlParameter[] sqlparams = new SqlParameter[1]; sqlparams[0] = new SqlParameter("@UserId", SqlDbType.NVarChar); sqlparams[0].Value = int.Parse(context.Session[Constant.SESSION_USERID].ToString()); String SessionId = (string)SqlHelper.ExecuteScalar(connstring, CommandType.StoredProcedure, "sp_GetUserSessionID", sqlparams); if ((context.Session["SesId"] == null) || (context.Session["SesId"].ToString() == "") || (context.Session["SesId"].ToString().Trim() != SessionId.Trim())) { FormsAuthenticationHelper.SignOutAndRedirectToLogin(); } } }
/// <summary> /// Checks if user has already logged in /// if not, redirects back to login page /// if so, continue /// </summary> public static void AuthenticateUser() { HttpContext context = HttpContext.Current; if (context.Session["UserId"] == null) { FormsAuthenticationHelper.SignOutAndRedirectToLogin(); } }