简体   繁体   中英

Limit input of user one per session per item

I have list of products in the database that I show in the GridView. Each row in the Grid has a text box and Button along with Name and description of the product. The button is used to send the comment for that specific button. Everything works fine now I want to limit the comment once per session. So a user will be able to send comment for a product and then button will be disabled. Now the products count can be 10 or 1000. What will be the best and efficient approach to achieve this. Should I save the product id and session id in the Session or in database or there can be some other easy way.

I haven't mentioned any code because I am just asking for best possible way to achieve the task.

let's understand the meaning of your suggestions:

using a session:

you are opening a session key at your server and map a list of id's which already had commented. you can match a specific product against this session and determine if the product can be commented or not.

pros: very elegant and easy to maintence solution cons: a user which request your website (say from another browser) will be able to comment product since the session is per connection and not per user

using a database:

same as session, only the data is durable because it is stored by the database.

pros: full control whenever users are able to comment a product or not cons: must identify each user with unique key (like id) and store that information in the db as well

other alternatives:

cookie on client side - setting up a cookie that will store the information. pros: each machine saves it's own cookies (not the server) cons: each cookie need to identify the user (or else several users on the same machine will be blocked). cookies can be cleaned

local storage on client side - same as cookie for that matter

so it semms you will need to work for it a little bit.. or else the functionallity will be problematic in some scenarios

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