什么是在asp.mvc中的请求之间存储数据的正确方法

时间:2020-12-11 16:57:44

My application reads barcodes from USB scanner. I treat them as tokens and then build commands from those tokens. There maybe a situation that I need 2 or more reads before I can create a command. I need to store previous reads in some way. Actually what is the correct way to keep some data between request? I do not to use that tokens in my view.

我的应用程序从USB扫描仪读取条形码。我将它们视为令牌,然后从这些令牌构建命令。在创建命令之前,我可能需要2次或更多次读取。我需要以某种方式存储以前的读取。实际上,在请求之间保留一些数据的正确方法是什么?在我看来,我不会使用这些令牌。

Only results of commands may be displayed in the view.

只有命令的结果可能会显示在视图中。

2 个解决方案

#1


8  

The TempData dictionary is ideal for storing data between controller actions. It's most commonly used in the Post/Redirect/Get pattern but could apply here.

TempData字典非常适​​合在控制器操作之间存储数据。它最常用于Post / Redirect / Get模式,但可以在此处应用。

This is a good article to read about it: http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html

这是一篇很好的文章:http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html

#2


7  

Here are a couple of possibilities that come to mind:

以下是一些可能的想法:

On the client:

在客户端:

  • Cookie
  • 曲奇饼
  • Hidden fields
  • 隐藏的领域

On the server:

在服务器上:

  • Cache (make sure to use user specific key to avoid collisions)
  • 缓存(确保使用用户特定的密钥以避免冲突)
  • Some backend storage (such as a database)
  • 一些后端存储(例如数据库)
  • ASP.NET Session
  • ASP.NET会话

#1


8  

The TempData dictionary is ideal for storing data between controller actions. It's most commonly used in the Post/Redirect/Get pattern but could apply here.

TempData字典非常适​​合在控制器操作之间存储数据。它最常用于Post / Redirect / Get模式,但可以在此处应用。

This is a good article to read about it: http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html

这是一篇很好的文章:http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html

#2


7  

Here are a couple of possibilities that come to mind:

以下是一些可能的想法:

On the client:

在客户端:

  • Cookie
  • 曲奇饼
  • Hidden fields
  • 隐藏的领域

On the server:

在服务器上:

  • Cache (make sure to use user specific key to avoid collisions)
  • 缓存(确保使用用户特定的密钥以避免冲突)
  • Some backend storage (such as a database)
  • 一些后端存储(例如数据库)
  • ASP.NET Session
  • ASP.NET会话