Asp.net mvc 4 ASP.net MVC 4站点在第一次请求数据库时速度变慢
我有一个ASP.net MVC 4站点,它在第一次请求时就会变慢。我在运行应用程序时尝试了断点。在登录过程中,它几乎会在我的第一次数据库查询时停留一分钟:Asp.net mvc 4 ASP.net MVC 4站点在第一次请求数据库时速度变慢,asp.net-mvc-4,server-error,Asp.net Mvc 4,Server Error,我有一个ASP.net MVC 4站点,它在第一次请求时就会变慢。我在运行应用程序时尝试了断点。在登录过程中,它几乎会在我的第一次数据库查询时停留一分钟: var InstnCode = form["code"].ToString(); var ComAccount = Context.Companies.Where(x => x.CompanyCode == InstnCode); 之后一切都很顺利 为什么会这样?我怎样才能纠正这个过程。由于这个问题,有时会出现服务器超时错误
var InstnCode = form["code"].ToString();
var ComAccount = Context.Companies.Where(x => x.CompanyCode == InstnCode);
之后一切都很顺利
为什么会这样?我怎样才能纠正这个过程。由于这个问题,有时会出现服务器超时错误
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(UserProfile model, string returnUrl, FormCollection form)
{
var InstnCode = form["code"].ToString();
var ComAccount = Context.Companies.Where(x => x.CompanyCode == InstnCode);
if (ComAccount.Any())
{
var modelvalue =
(from d in Context.UserProfiles
where d.UserName == model.UserName && d.Password == model.Password && d.Company.CompanyCode == InstnCode
select d).FirstOrDefault();
if (modelvalue != null)
{
string code = null;
Session["UName"] = modelvalue.UserName;
Session["Theme"] = modelvalue.Theme;
Session["InstnName"] = modelvalue.Company.CompanyName;
Session["Role"] = modelvalue.Role.RoleName;
Session["StartUp"] = modelvalue.StartUp;
var permission =
Context.AccountPermissions.Where(x => x.RoleId == modelvalue.RoleId)
.AsQueryable()
.FirstOrDefault();
if (permission != null)
{
SetSessions(permission, "yes");
}
else
{
SetSessions(permission, "no");
}
if (modelvalue.CompanyId != 0 && modelvalue.StaffId == null && modelvalue.StudentProfileId == null)
{
Session["ComID"] = modelvalue.CompanyId;
code = modelvalue.Company.CompanyCode;
}
else if (modelvalue.CompanyId != 0 && modelvalue.StudentProfileId != null)
{
var student =
(from d in Context.StudentProfiles
where d.StudentProfileId == modelvalue.StudentProfileId
select d).FirstOrDefault();
code = student.Company.CompanyCode;
Session["ComID"] = student.CompanyId;
}
else if (modelvalue.CompanyId != 0 && modelvalue.StaffId != null)
{
var staff =
(from d in Context.Staff where d.StaffId == modelvalue.StaffId select d).FirstOrDefault();
code = staff.Company.CompanyCode;
Session["ComID"] = staff.CompanyId;
Session["StaffID"] = staff.StaffId;
}
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect");
return View(model);
}
}
ModelState.AddModelError("", "The institution code provided is incorrect");
return View(model);
}
这是我的登录功能。我正在使用
@使用(Html.BeginForm(“Login”,“Account”,FormMethod.Post,new{enctype=“multipart/formdata”}))
作为我的登录表单
任何帮助都将不胜感激。
提前感谢可能不仅仅是数据库: