[英]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.