首页 > 解决方案 > 在 IIS 上运行的 ASP.net 上的超长 TTFB

问题描述

我目前正在建立一个创建自定义计算机的网站,但是我的问题是我的 TTFB 在我的家庭 IIS 服务器上运行时非常慢。我在这台服务器上运行了多个网站,这是唯一一个具有 20-30 秒 TTFB 的网站。

我已经使用webpagetest.org来测试我的网站并得到这个瀑布图像

但是,然后我使用 VS 和 chrome 自己的开发工具对我的网站进行调试测试,我的水落在这里给了我 1 秒钟。我想知道如何在服务器或我的页面中诊断和测试可能导致此问题的问题。这是我的主页代码片段,供任何想知道的人使用 - 控制器:

namespace ComputerSite.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

布局(页面中唯一没有静态内容的部分):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Computers for you!</title>
@Styles.Render("~/Content/boot")
@Scripts.Render("~/bundles/modernizr")

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/ajaxgroup")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/datatables")
@Scripts.Render("~/bundles/tawk")
@if (Request.IsAuthenticated)
{
    string text = UserHelper.GetUserEmail(User.Identity.Name), key = "MY APIKEY";
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

    Byte[] textBytes = encoding.GetBytes(text);
    Byte[] keyBytes = encoding.GetBytes(key);

    Byte[] hashBytes;

    using (System.Security.Cryptography.HMACSHA256 hash = new System.Security.Cryptography.HMACSHA256(keyBytes)) { hashBytes = hash.ComputeHash(textBytes); }

    string hashTxt = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();

    <script type="text/javascript">
        Tawk_API.onLoad = function(){
        Tawk_API.setAttributes({
        'name' : '@User.Identity.Name',
            'email': '@UserHelper.GetUserEmail(User.Identity.Name)',
        'hash': '@hashTxt'
}, function (error) {});

};
    </script>
}
@RenderSection("scripts", required: false)
</head>
<body>
@{ Html.RenderPartial("_navBar"); }
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - Building computer for you by you!</p>
    </footer>
</div>

</body>
</html>

根据要求,我创建了一个全新的 ASP.net 网站并对其进行了调试,由此我得到了一个加载时间为 270 毫秒和 TTFB 为 12 毫秒的瀑布

标签: c#asp.net-mvciisweb-testing

解决方案


推荐阅读