TempData: Is It Safe?

前端 未结 5 2247
南笙
南笙 2021-02-18 15:04

I am using the TempData in order to preserve my model in when using a RedirectToAction. It works fine, but I have a nagging feeling that it might not b

5条回答
  •  悲哀的现实
    2021-02-18 15:41

    Session state can work in a clustered environment, providing that one of two things happens

    1. Your load balancer supports "sticky" sessions (i.e. all requests in a given session are routed to the same machine)
    2. You configure the session provider to use an out of process session provider, you can use either the ASP.NET State Service or the SQL Session State Provider

    The question of whether you should use tempdata or not is a different question altogether. I would argue that there is usually a way around it. If you are trying to avoid a hit to the database to reload an object that one action has already loaded, look at using a cache instead.

提交回复
热议问题