Is web session “Bad Design”? Why?

the other day I was discussing with a colleague and he came out saying that using user’s session in a web application is just wrong. I replied that it could be wrong depending by the information you are storing, otherwise why should a web session service even being provided by Microsoft (we were talking about ASP.NET).

He replied to me, again, that even in MS they could easily reply me that it was bad design. And that he could show me some white-papers demonstrating that.

Unfortunately I have no opportunity to contact this guy anymore, but I would really like to understand more about his point of view. Does anyone have information/points of view about that here?

3

I don’t think he meant “Bad design” so much as “Bad practice.” Generally speaking, a web application should be as stateless as conceivably possible. Even though, for example, you may need to know user information in order to authorize page viewing, that information could be saved on the client machine in the form of a cookie and the server simply validates the user information each and every time.

That would be ideal, but you can’t always count on the client being able to save cookies. Furthermore, it involves validating the user in a stateless fashion, which potentially involves querying information from the database for a simple page request. Often times it’s just simpler to save such information in the session.

However, once you’ve crossed the Rubicon, a lot of programmers are tempted to save not only authentication info in the session but many other things as well. This is an anti-pattern and tends to make your web application heavily dependent upon state, which is precisely what was supposed to be avoided in the first place.

Some programmers would hinge on technology like Spring (if you’re using Java) to untangle what would otherwise be a mess of dependencies, but I would argue that that only makes it easier to create dependencies rather than eliminate them. Such technologies should aid your development, not make your anti-pattern less of a problem.

Therefore, a good rule of thumb is that if you can write it stateless, it is probably a better idea to do so or you risk to fall into this trap. Obviously you’re going to run into situations in which this is required, but generally speaking, you should only save information that would otherwise be difficult to reacquire.

2

I think you’re confusing two different topics: 1) sessions and 2) the page model of asp.net webforms

A web session is necessary for authentication a user. Ideally a session should only be used for this purpose. You shouldn’t store user data in a session (whether it be on the server, in a cookie, or as asp.net/webforms does it: within the page itself). No one should say that a web session is bad, but rather, storing user data in a session is a bad practice. The reasons for not storing user data on the server include the same reasons to avoid global variables. Storing user data in cookies or in the page can introduce security issues. Using the page model of asp.net also doesn’t adhere to the stateless nature of the web. You could do a search to find out more about why webforms is a bad design. Sessions on the other hand are a necessary part of web applications.

2

Controls and storing session state on a page are essentially a hack. Is the case of MS – a necessary one as they wanted to be able to provide a development environment where you could design pages as you can in winform environments.

MS have themselves moved towards the MVC architecture (latest version – MVC 4) which is more of a return to what the protocol actually should be – stateless.

There are situations where storing state is still handy but it should be understood that this is the exception rather than the rule.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật