asp.net-mvc – 加载登录表单时网站速度慢
我有一个我正在开发的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”> ViewEngines.Engines.Clear(); EDIT1: 根据您上次的评论,提到该应用程序在您的本地IIS中正常运行.我建议您开始专注于分析远程IIS上的请求,这是一个可以使用的工具link. 为了追踪成功的请求(你应该在你的情况下这样做)将状态设置为200,这里也是tutorial. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET (C#) 应用篇-数据列分页操作-01_Adapter_Fill
- asp.net-mvc – MVC:存储库和服务
- asp.net-mvc – 如何清除ASP.NET MVC应用程序中文本框的发布
- 从未调用ASP.NET Web API自定义JsonConverter
- asp.net – FF和IE不从CSS加载img src
- asp.net-mvc-4 – 重载Html.LabelFor以添加’后缀’的简单方
- asp.net – 403禁止错误
- 为什么System.Attribute的GetHashCode方法需要如此设计?
- ASP.NET Webforms,用户控件中的JavaScript
- asp.net-mvc – Sitecore在我的MVC解决方案中提供了一个空白
- asp.net-mvc – 为什么validateantiforgerytoken
- 如何显示或隐藏基于角色的控件 – ASP.NET MVC 4
- ASP.NET -- 一般处理程序ashx
- asp.net – 电子邮件CSS
- asp.net – HttpContext.Cache到期
- 处理ASP.NET MVC中日期的最佳方法 – Javascript
- asp.net – 表单身份验证保护什么,而不是使用会话
- asp.net-mvc – 在Controller操作方法中重用代码
- asp.net-mvc-4 – MVC SiteMap – 当不同节点指向
- asp.net-mvc – 嵌套对象的远程ViewModel验证无效