angularjs - 在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) {
});
};
解决方案
推荐阅读
- sql - 为什么我的 SELECT 语句在 SELECT MAX(ID) 时返回 2 行?
- machine-learning - 是否可以逐步训练 sklearn 模型(例如 SVM)?
- python - SQL 查询列不存在
- php - 如何在laravel 5中存储excel表格中的图像
- c# - 如何让 C# WPF MVVM 屏幕保护程序使用双显示器?
- mysql - 我想从 table1 操作“AS 年龄”列
- ruby - 旧宝石是否总是适用于更高版本的 ruby?
- laravel - Laravel:hasMany 关系使用 where 子句中断查询
- c# - 如何让 Parent 只使用它的游戏对象而不被子类访问?
- c++ - 分配给 std::vector 元素会导致内存损坏