加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 加载登录表单时网站速度慢

发布时间:2020-12-16 03:30:04 所属栏目:asp.Net 来源:网络整理
导读:我有一个我正在开发的ASP.NET MVC网站,我最近将它部署在测试服务器上,以便客户端可以提供一些初步反馈. 我注意到在实时服务器上加载登录表单有相当大的延迟,大约20-30秒.登录后,系统运行正常,并且响应迅速. 如果您注销,并返回登录页面,它再次变慢. 它似乎不
我有一个我正在开发的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();
    }

和帐户控制器:

[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);
    }

解决方法

一些事情会提高性能:

>首先:如果您关心性能,请在发布模式下部署您的网站.这是Dave Ward关于它的article.

< compilation targetFramework =“您的框架版本”debug =“false”>
>如果你没有使用webforms视图引擎(我假设你不是)jus禁用它并仅使用Razor并进一步使用它,只允许chtml文件

ViewEngines.Engines.Clear();
IViewEngine RazorEngine = new RazorViewEngine(){FileExtensions = new string [] {“cshtml”}};
ViewEngines.Engines.Add(RazorEngine);
>配置应用程序池(IIS 7)Here’s the link的空闲超时设置

EDIT1:

根据您上次的评论,提到该应用程序在您的本地IIS中正常运行.我建议您开始专注于分析远程IIS上的请求,这是一个可以使用的工具link.

为了追踪成功的请求(你应该在你的情况下这样做)将状态设置为200,这里也是tutorial.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读