public static List<Account> GetPagedCustomers(int skip, int take) { using (var context = new DbTESTEntities1()) { var query = context.Account .OrderBy(c => c.id ); return query.Skip(skip).Take(take).ToList(); } }
public ActionResult Login(Account model, string returnUrl) { if (ModelState.IsValid) { using (DbTESTEntities1 entities = new DbTESTEntities1()) { string username = model.name; string password = model.password; // Now if our password was enctypted or hashed we would have done the // same operation on the user entered password here, But for now // since the password is in plain text lets just authenticate directly Account userValid = entities.Account.SingleOrDefault(user => user.name == username && user.password == password); // User found in the database if (userValid!=null) { string userdata = userValid.roles; string formsCookieStr = string.Empty; HttpContext currentContext = System.Web.HttpContext.Current; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, username, DateTime.Now, DateTime.Now.AddMinutes(30), false, userdata, FormsAuthentication.FormsCookiePath); formsCookieStr = FormsAuthentication.Encrypt(ticket); HttpCookie FormsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, formsCookieStr); currentContext.Response.Cookies.Add(FormsCookie); //FormsAuthentication.SetAuthCookie(username, false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } // 如果執行到這裡,發生某項失敗,則重新顯示表單 return View(model); }