gpt4 book ai didi

asp.net-mvc - 网站加载登录表单缓慢

转载 作者:行者123 更新时间:2023-12-04 20:01:31 26 4
gpt4 key购买 nike

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

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

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

apppool 缓存似乎不是问题,因为它每次都在页面上发生,而不仅仅是一次,而且所有项目似乎都在加载。

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

下面是所有 Controller 继承的 BaseController,加上帐户登录 Controller 。

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

和帐户 Controller :
    [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);
}

最佳答案

有几件事可以提高性能:

  • 首先也是最重要的:在 中部署您的站点Release 如果您对性能有任何关心的话。这里很棒article来自戴夫·沃德 (Dave Ward)。
    <compilation targetFramework="your framework version" debug="false">
  • 如果您没有使用 webforms查看引擎(我认为您不是)只需禁用它并使用 Razor只是为了更进一步,只允许 chtml 文件
    ViewEngines.Engines.Clear();
    IViewEngine RazorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };
    ViewEngines.Engines.Add(RazorEngine);
  • 为应用程序池 (IIS 7) 配置空闲超时设置 Here's the link


  • 编辑1:

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

    为了跟踪成功的请求(并且您应该在您的情况下这样做)设置 status 200 这是一个 tutorial也是如此。

    关于asp.net-mvc - 网站加载登录表单缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29378095/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com