Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 初始SQL数据库连接非常慢_Angularjs_Asp.net Mvc - Fatal编程技术网

Angularjs 初始SQL数据库连接非常慢

Angularjs 初始SQL数据库连接非常慢,angularjs,asp.net-mvc,Angularjs,Asp.net Mvc,我开发了一个asp.net mvc/angular网站,它在我的本地机器上运行良好,但是当上传到我的GoDaddy共享主机帐户时,创建初始数据库连接需要花费很长时间,当用户第一次尝试登录该网站时&我不知道如何修复,我知道我总是可以移动到更好的主机,但是我想看看是否有任何编码解决方案我可以首先尝试&这不是我在代码中遗漏的问题 这是我的网站:whesearchreporting.com 尝试使用任意随机登录登录&您会注意到,接收无效登录消息大约需要15-20秒。注意:这只会影响第一个登录网站的人。似

我开发了一个asp.net mvc/angular网站,它在我的本地机器上运行良好,但是当上传到我的GoDaddy共享主机帐户时,创建初始数据库连接需要花费很长时间,当用户第一次尝试登录该网站时&我不知道如何修复,我知道我总是可以移动到更好的主机,但是我想看看是否有任何编码解决方案我可以首先尝试&这不是我在代码中遗漏的问题

这是我的网站:whesearchreporting.com

尝试使用任意随机登录登录&您会注意到,接收无效登录消息大约需要15-20秒。注意:这只会影响第一个登录网站的人。似乎一旦用户尝试连接,任何试图访问该站点的add'l用户都可以立即登录

以下是我迄今为止的观察结果:

这只影响初始登录,即初始数据库连接。一旦你进入,你可以点击网站上的任何东西,甚至可以毫无问题地注销并重新登录

如果我登录到计算机A(这需要一些时间),那么我几乎可以立即以其他用户的身份登录到计算机B

我读到GoDaddy超载了他们的共享主机服务器,所以我认为这是罪魁祸首,但不是积极的

下面是我的一些代码:

角度代码:

 angular.module('dashboardApp', [])
.controller('loginController', function ($scope, $location, $window, LoginService) {
    $scope.IsLoggedIn = false;
    $scope.Message = '';
    $scope.Submitted = false;
    $scope.IsFormValid = false;

    $scope.AccountData = {
        Email: '',
        Password: ''
    };

    //Check is the form valid or not. 
    $scope.$watch('frmLogin.$valid', function (newVal) {            
        $scope.IsFormValid = newVal;
    });

    $scope.Login = function () {
        $scope.loading = true;
        $scope.Submitted = true;
        if ($scope.IsFormValid) {
            LoginService.GetUser($scope.AccountData).then(function (d) {
                if (d.data.Email != null) {
                    $scope.IsLoggedIn = true;
                    $window.location.href = "/Account/Dashboard";
                }
                else {
                    $scope.Message = "Invalid login";
                    $scope.loading = false;
                }
            });
        }
    };
})

.factory('LoginService', function($http) {
    var fac = {};
    fac.GetUser = function (d) {
        return $http({
            url: '/Home/UserLogin',
            method: 'POST',
            data: JSON.stringify(d),
            headers: { 'content-type': 'application/json' }
        });
    };
    return fac;
 });
我的家庭控制器:

My AccountRepository登录方法:

最后,我的数据库连接获取帐户信息:

 private readonly Connection _conn;

 public Account GetAccountByEmail(string email)
 {
        Account account;

        using (MySiteEntities db = _conn.GetContext())
        {
            account = (from c in db.Accounts
                      where c.Email.Equals(email)
                      select c).FirstOrDefault();
        }

        return account;
}
你知道为什么最初的连接如此缓慢吗?你有没有想过我可以做些什么来提高性能


谢谢

你知道GoDaddy是否在使用Windows服务器吗?因为这听起来像是IIS的问题,所以在一段时间不使用后,它会进入休眠状态。您可以更改此设置,但据我所知,您无法将其关闭。

是的,它是一个共享的Windows服务器。因此,这就是您要查找的内容:它与GoDaddy相关。我们更换了主机提供商&现在没有减速问题。
public string Login(Account a)
    {
        Account account = _accountRepository.GetAccountByEmail(a.Email);
        a.Password = a.Password.Encrypt(a.Email);

        if (account != null)
        {
            //password matches
            if(account.Password == a.Password)
            {
                return account.Email;
            }
            else
            {
                return null;
            }
        }

        return null;             
    }
 private readonly Connection _conn;

 public Account GetAccountByEmail(string email)
 {
        Account account;

        using (MySiteEntities db = _conn.GetContext())
        {
            account = (from c in db.Accounts
                      where c.Email.Equals(email)
                      select c).FirstOrDefault();
        }

        return account;
}