首页 > 解决方案 > 在angularjs中成功调用后出现err_connection_timed_out

问题描述

我正在使用 AngularJs 的 http 服务,它运行成功。但是从过去三个月开始,我在 1 到 2 次成功调用后收到 err_connection_timed_out。如果我重新加载页面,那么错误就会消失。

我使用 ASP.Net MVC 作为后端应用程序,它使用 Cookies 进行会话管理。

任何人都可以帮助如何解决这个问题?

全球.asax.cs

protected void Application_BeginRequest(Object sender, EventArgs e)
{
   HttpContext.Current.Items["dbkey"] = new DBEntities();
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
   var entityContext = HttpContext.Current.Items["dbkey"] as DBEntities;
            if (entityContext != null)
                entityContext.Dispose();
}

登录控制器

public JsonResult JsonLogin(string email, string password)  
{
  // Hashed ticket
  string hashCookies = FormsAuthentication.Encrypt(ticket);
  HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
  cookie.Expires = expiryDate;
  Response.Cookies.Add(cookie);
  HttpCookie mycookie = new HttpCookie("cookieName");
  HttpContext.Current.Response.Cookies.Set(mycookie);
}

员工控制器

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    HttpCookie cookie = HttpContext.Current.Request.Cookies["cookieName"];         
    if (cookie == null || string.IsNullOrEmpty(User.Identity.Name))
    {                
      filterContext.Result = new RedirectResult("/Login/Index");
    }
    base.OnActionExecuting(filterContext);
}

public JsonResult GetData()
{
  var res = entityContext.StaffData.Where(...).ToList();
  return Json(res, JsonRequestBehavior.AllowGet);            
}

数据.js

var app = angular.module('StaffApp', []);
app.controller('StaffCtrl', function ($scope, $http) {
    $scope.GetData = function () {
        $http.get("/Staff/GetData")
            .then(function (response) {
                let data = response.data;
                if (data.length > 0) {
                    angular.forEach(data, function (fm, key) {
                        $scope.Staffs.push(fm);
                    });
                }                
            }, function (response) {                
            });
    };

标签: angularjsajax

解决方案


推荐阅读