简体   繁体   English

将**敏感数据**从一个操作方法控制器传递到另一个控制器操作方法控制器的最佳方法是什么

[英]What is the best way to pass the **sensitive data** from one action method controller to another controller action method controller

Here am using TempData["Amount"] to pass the total cart amount from one controller action to another action method. 这里使用TempData["Amount"]将总购物车金额从一个控制器动作传递到另一个动作方法。 so I had a doubt its good practice to use TempData["Amount"] pass sensitive information from one action method to another action method . 所以我怀疑使用TempData["Amount"]将一个动作方法中的敏感信息传递给另一个动作方法的好习惯。 what's the life time of time data (like sessions 20 mins) and how handle the exception of TempData["Amount"] . 什么是时间数据的生命时间(如sessions 20分钟)以及如何处理TempData["Amount"]的异常。

if (adoptionDetails != null)
      {
        foreach (var m in adoptionDetails.animalAdaptionDetails.ToList())
          {
            amount += Convert.ToInt32(m.amount);
            animalNames += m.name;
             animalNames += ",";
           }
        ViewBag.Amount = amount;
        ViewBag.animalsName = animalNames;
        TempData["Amount"] = amount;
        return View(adoptionDetails);
       }
else
     {
        return View("~/Views/Users/Errorpage.cshtml");
      }

TempData is tied to a user by the same logic that ties a Session to a user. TempData通过将会话绑定到用户的相同逻辑绑定到用户。

TempData is only available for the next request sent by the same session after which it is automatically deleted. TempData仅适用于同一会话发送的下一个请求,之后会自动删除。

TempData is held in-memory in the server, only when you insert it into the response is it transmitted to the client. TempData保存在服务器的内存中,只有当您将其插入响应时才会传输到客户端。

You can start thinking about it in a different way. 你可以用不同的方式开始思考它。

You have some user data, whatever it is, which you need to make available to your application in multiple places. 您有一些用户数据,无论它是什么,您需要在多个位置提供给您的应用程序。 One option is the session, it is user bound, it is short lived and works well provided you don't store too much in it. 一个选项是会话,它是用户绑定的,它是短暂的并且运行良好,只要你不存储太多。

Once you have the data in one place, you no longer have to think about passing it between controllers, instead you start to pull it, wherever you need it. 一旦您将数据放在一个地方,您就不再需要考虑在控制器之间传递数据,而是开始在任何需要的地方拉动数据。 You could start building some services which you can use to work with your storage. 您可以开始构建一些可用于处理存储的服务。 I said session, but you can just as easily use something else, like an actual database, which for things like shopping carts is not a bad idea. 我说会话,但你可以轻松地使用其他东西,比如一个真正的数据库,对于像购物车这样的东西来说并不是一个坏主意。

The idea here is to stop thinking from the point of view of MVC and start to think at application level. 这里的想法是从MVC的角度停止思考,并开始在应用程序层面思考。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将消息从动作控制器传递到另一个动作控制器的最佳方法是什么 - What's the best way to pass a message from an action controller to another action controller 如何从一个控制器操作方法路由到另一个控制器操作方法而不在MVC 5中显示控制器名称 - How to route from one controller action method to another controller action method without displaying controller name in MVC 5 从另一个动作调用控制器中的动作方法 - Calling action method in the controller from another action 将数据从一个控制器动作传递到ASP.Net MVC 5中的另一个控制器动作 - pass data from one controller action to another controller action in ASP.Net MVC 5 将变量从视图传递到 controller 操作方法,然后传递到同一 ASP.NET MVC controller 中的另一个方法 - Pass a variable from a view to a controller action method and then to another method in the same ASP.NET MVC controller 将数据从视图剃刀页面传递到控制器中的操作方法 - Pass data from view razor page to action method in controller 使用 One From Action 方法覆盖 Controller 上的 ResourceFilter - Overriding ResourceFilter on Controller With One From Action Method 如何在MVC C#中从另一个Action方法(都在同一个Controller中)调用一个Action方法? - How to call one Action method from another Action method(both are in the same Controller) in MVC C#? 从一个视图路由到另一个控制器的操作方法,并将参数传递给该控制器的构造函数 - Routing from one view to another controller's action method and passing a parameter to that controller's constructor 在Controller操作方法中重用代码的最佳方法 - Best Way to reuse code inside my Controller action method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM