Using cookies to store session in ASP MVC

前端 未结 6 1612
野性不改
野性不改 2021-02-03 10:28

Storing the entire session in a cookie has been standard in Rails for the last few years - is there an easy way to achieve something similar with ASP MVC?

By default, an

6条回答
  •  没有蜡笔的小新
    2021-02-03 11:04

    I would strongly discourage storing the entire session in cookies. It has bad performance implications. Consider this: every request (to every resource) will contain an overhead of possibly stale data that you only need once or twice. Eventually this overhead will hit your users, your bandwidth and your site performance.

    Here's an example:

    GET / HTTP/1.1
    Host: localhost
    OtherUsefulHeaders: foo
    Cookie: YourSessionState=...
    

    Initial request size is around 200 bytes. Let's say, you add around 100 bytes to your session. Now the size is 300 bytes and overhead is ~30%. You add another 100 bytes, and overhead is 50%. Which means it roughly requires 2x time to send the request and 2x bandwidth.

    You should rather look into cookie-based TempData implementation as it has much smaller footprint and actually makes sense.

提交回复
热议问题