问题标签 [application-variables]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1033 浏览

php - PHP 应用程序全局变量

我想存储一个只要应用程序正在运行并且可以从所有会话访问的全局变量。我试过 $GLOBALS 但它不耐用。这是临时的,我存储了数据,当我再次请求相同的代码时,它说这个索引无法识别。

我必须将我的值存储在文件中吗?

编辑 :: 这是一个始终打印“未设置”的示例代码

0 投票
0 回答
331 浏览

c# - 索引超出了应用程序变量的数组边界

我有一个 ashx 网页,可以进行一些轻量级的数据处理。我正在计时进程持续时间,并且每次调用都将这个持续时间保存在应用程序变量中,以便稍后我可以进行一些统计(例如每分钟的平均进程持续时间)。

几个月来,所有这一切都运行良好,直到最近我开始在将新持续时间添加到数组的行上出现错误。错误是:

System.IndexOutOfRangeException:索引超出了数组的范围。在 System.Collections.Generic.List`1.Add(T item) at S01Service.ProcessRequest(HttpContext context) in c:\inetpub\wwwroot\BigServices\S01.ashx:line 79 at System.Web.HttpApplication.CallHandlerExecutionStep.System System.Web.HttpApplication.ExecuteStep 处的 .Web.HttpApplication.IExecutionStep.Execute()(IExecutionStep 步骤,布尔值和同步完成)

回到正轨的唯一方法是在对页面的调用失败时回收 IIS 池。然后这可以在再次失败之前再正常工作几周。

我的问题:

  • 为什么在上一行声明变量时索引超出数组边界(如果为null)
  • 我在做什么是“好习惯”吗?不使用数据库记录持续时间的原因纯粹是出于速度目的(节省内存是即时的,而我会浪费宝贵的毫秒来调用数据库)。

以防万一,此页面每分钟被调用约 2500 次

0 投票
2 回答
583 浏览

c# - 在 MVC 控制器中,Page.Application(在 .aspx.cs 页面中)的等价物是什么

我正在开发 MVC Web 应用程序,并且正在使用.Dlls. 的一些其他项目。同样的 .dll 也在我的另一个 Web 应用程序中使用,该应用程序是在 WebForms (.aspx) 页面中制作的。

现在我的问题是:该 .dll 中的某些函数被接受 Page.Application为参数。在 .aspx 页面中运行良好。但现在我想在 MVC 应用程序中使用相同的功能。但是在MVC controller我无法访问那个Page.Application

所以请有人可以帮助我如何在 MVC 控制器中访问以及在MVCPage.Application控制器中是否有任何等价物Page.Application

谢谢,

编辑:- 我不是在问Application variable-我在问Page.Application哪个是HttpApplicationState. 我想要这个HttpApplicationState在 MVC 控制器中

0 投票
1 回答
46 浏览

c# - 应用程序变量中的实例

实例化类并将它们保存在应用程序变量中然后使用它们并且不必在每个请求中实例化它们是否正确?

例如:实例化一个 DbContext 并在每次需要时直接从 de Application 变量中使用它。

这意味着性能的真正提升?

在全球 asa 中:

然后使用:

0 投票
1 回答
70 浏览

c# - 在 ASP.NET、C# 中使用会话/应用程序变量的按钮和 DropDownList

我将如何实现这个场景?我在默认页面上有两个按钮,Button1 和 Button2。如果单击 Button1,则第二页上 DropDownList 的内容将是:a、b 和 c。但是,如果从 Default 页面单击 Button2,则第二页上的 DDL 的内容将是:d 和 e。谢谢!

0 投票
0 回答
31 浏览

asp.net - How do we store multiple objects in application variable?

I am trying to create a small web application. I am facing little bit of difficulty with State management in Asp.Net. Even though it is not advisable to store data in application variable, just creating this to understand more about state management.

I am trying to capture user information from a web page, store it in a List and add the List to a Application variable so as to iterate through the stored user values(say user email) and check if the user exist or not.

While testing, I am able to capture the values entered by the first user and when second user enters data, it is getting captured in the application variable but it replaces objects created by the first user.

Is there a way to add multiple objects to application variable and iterate through them? I have declared Application variable in global.asax.cs under Application_Start I have tried the following,

0 投票
2 回答
1262 浏览

c# - 如何在 .Net Core 2.0 中创建应用程序变量?

我已经使用.Net Core 2.0. 现在我想存储一些不是用户特定的值,我想让这些值在所有登录的用户之间共享。所以我可以使用Application Variable. 但是.Net Core 2.0没有内置的方法来实现这一点。

我试过的

我创建了一个类,如下所示。

在那之后,我在方法下的Startup.cs文件下ConfigureServices写了下面的行。

services.AddSingleton<ApplicationLevelData>();

在每个Controller我需要注入该服务如下。

私有 ApplicationLevelData _appData;

之后,我们可以在整个Controller.

但是,我不要这个Inject东西。我们可以使用 使应用程序数据可用HttpContext吗?

谁能建议我如何Application variable创建.Net Core 2.0

任何帮助将不胜感激。

谢谢。