简体   繁体   中英

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. so I had a doubt its good practice to use TempData["Amount"] pass sensitive information from one action method to another action method . what's the life time of time data (like sessions 20 mins) and how handle the exception of 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 is only available for the next request sent by the same session after which it is automatically deleted.

TempData is held in-memory in the server, only when you insert it into the response is it transmitted to the client.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM