加载登录表单时网站速度慢

Gav*_*tes 5 asp.net-mvc entity-framework

我有一个我正在开发的ASP.NET MVC网站,我最近将它部署在测试服务器上,以便客户端可以提供一些初步反馈.

我注意到在实时服务器上加载登录表单有相当大的延迟,大约20-30秒.登录后,系统运行正常,并且响应迅速.

如果您注销,并返回登录页面,它再次变慢.

它似乎不是apppool假脱机的问题,因为它每次都发生在页面上,而不仅仅是一次,并且所有项目似乎都在加载.

关于如何调试这个的任何建议?

下面是所有控制器enherit的BaseController,以及帐户登录控制器.

protected override void ExecuteCore()
    {



        if (User.Identity.IsAuthenticated)
        {
            try
            {
                AccountDataContext = new AccountDAL.DataContext(ConfigurationManager.AppSettings["Server"]);
                // set the current user. 
                CurrentUser = AccountDataContext.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
                AccountDataContext.CurrentAccount = CurrentUser.Account;
                ViewBag.CurrentUser = CurrentUser;
                ViewBag.Account = CurrentUser.Account;

                SystemDataContext = new SystemDAL.DataContext(ConfigurationManager.AppSettings["Server"], CurrentUser.Account.Database);

                // setup the account based on the users settings
                ViewBag.Theme = "Default"; // hard coded for now
            }
            catch (Exception)
            {
                // if the previous threw an exception, then the logged in user has been deleted
                // log them out
                FormsAuthentication.SignOut();
                Session.Abandon();

                // clear the authentication cookie
                var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
                cookie.Expires = DateTime.Now.AddYears(-1);
                Response.Cookies.Add(cookie);

                FormsAuthentication.RedirectToLoginPage();
            }
        }

        base.ExecuteCore();
    }
Run Code Online (Sandbox Code Playgroud)

和帐户控制器:

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

    //
    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginViewModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {

            if(AccountDataContext == null)
                AccountDataContext = new AccountDAL.DataContext(ConfigurationManager.AppSettings["Server"]);

            var user = AccountDataContext.Users.FirstOrDefault(x => x.Email == model.UserName && x.Password == model.Password);
            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                return RedirectToLocal(returnUrl);
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
Run Code Online (Sandbox Code Playgroud)

Gav*_*tes 2

由于速度减慢似乎只影响登录页面,因此我仔细查看了它们都使用的帐户控制器(目前没有实现其他帐户功能)。

我在控制器顶部发现了以下代码:

public AccountController()
         : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
Run Code Online (Sandbox Code Playgroud)

删除此声明解决了该问题。我不确定它是什么或它来自哪里,我认为它来自原始的 MS 默认实现身份验证。我没有 ApplicationDbContext,因此我认为它正在等待此请求超时,然后再继续。