1
私はWebサイトで作業しています。私はMVC 5とWeb APIの両方を使用しています。 TTFBがWeb API要求に対して長すぎます(6〜10秒)が、mvcビューのttfb(1〜2秒)は許容されます。 同じapiに多くのリクエストを投稿すると、最初のリクエストのみが問題になります。投稿リクエストの時間(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") };
}