Asp.net mvc 如何减少post请求的时间(TTFB)?
我在一个网站上工作。我使用MVC5和WebAPI。 TTFB对于web api请求来说太长(6~10秒),但是mvc视图的TTFB(1~2秒)是可以接受的。 当我向同一个api发布许多请求时,只有第一个请求有问题 这是我在登录方法中的代码Asp.net mvc 如何减少post请求的时间(TTFB)?,asp.net-mvc,asp.net-web-api,Asp.net Mvc,Asp.net Web Api,我在一个网站上工作。我使用MVC5和WebAPI。 TTFB对于web api请求来说太长(6~10秒),但是mvc视图的TTFB(1~2秒)是可以接受的。 当我向同一个api发布许多请求时,只有第一个请求有问题 这是我在登录方法中的代码 现在我将我的应用程序部署到另一台服务器上,TTFB变得更短。而且该会话经常被删除的问题也得到了解决。现在我将我的应用程序部署到另一台服务器上,TTFB变得更短。而且该会话经常被删除的问题也得到了修复 public HttpResponseMessage
现在我将我的应用程序部署到另一台服务器上,TTFB变得更短。而且该会话经常被删除的问题也得到了解决。现在我将我的应用程序部署到另一台服务器上,TTFB变得更短。而且该会话经常被删除的问题也得到了修复
public HttpResponseMessage Login(LoginInfo loginInfo)
{
string result = JsonConvert.SerializeObject(new { status = "example" });
//check the whether user is already login
if (HttpContext.Current.User.Identity.IsAuthenticated
&& loginInfo.UserName == (string)HttpContext.Current.Session["user"])
{
result = JsonConvert.SerializeObject(new { status = (string)HttpContext.Current.Session["role"] });
return new HttpResponseMessage { Content = new StringContent(result, Encoding.UTF8, "application/json") };
}
Student student = studentRepo.GetById(loginInfo.UserName);
if (student == null)
{
result = JsonConvert.SerializeObject(new { status = "usr" });
}
else
{
string password;
string salt = (string)HttpContext.Current.Session["salt"];
if (string.IsNullOrEmpty(salt))
{
//the login page has expired
result = JsonConvert.SerializeObject(new { status = "expire" });
}
else
{
password = student.Password + salt;
password = MD5Helper.GetMd5(password);
if (password == loginInfo.Password)
{
//login success!
HttpContext.Current.Session.Remove("salt");
FormsAuthentication.SetAuthCookie(loginInfo.UserName, false);
HttpContext.Current.Session.Add("user", student.StuNo);
HttpContext.Current.Session.Add("role", student.Role);
result = JsonConvert.SerializeObject(new { status = student.Role });
}
else
{
result = JsonConvert.SerializeObject(new { status = "deny" });
}
}
}
return new HttpResponseMessage { Content = new StringContent(result, Encoding.UTF8, "application/json") };
}