C# .NET - In mvc What we use like view, session,Application in Asp.net ?

Asked By Afzal Ahmed Khan on 26-Jun-12 05:29 AM
Jitendra Faye replied to Afzal Ahmed Khan on 26-Jun-12 05:34 AM

You use session the same way you do in webforms.

In your controllers you can simply use the Session object. You could save the state of a model in Session and pass the result to your view.

refer this link-


RAJASEKHAR RAJENDRAN replied to Afzal Ahmed Khan on 27-Jun-12 04:22 AM
Hi Afzal,

You can use in the Same Ways you use in the Web Forms.

But when using the Sessions you need to be careful in considering the below.

There are drawbacks of using sessions:
  •  The sessions prevent a user to properly browse your site from multiple browser tabs, the changes made in one tab are reflected in all others.
  •  The sessions aren't persisted by default, and if you're operating on a web form, you need to save the sessions in your database to be accessible by every farm node. But it seems unlikely that you're scaling like this. And if you meet the scaling necessity, sessions won't be your top problems.
  • Sessions require additional functionality from the user's browser (typically, cookies). But modern browsers all support cookies, so you only have to worry about very special browsers.

There are also some benefits of the sessions over hidden inputs:

  •  The smaller overhead. Only a small session cookie is passed back and forth between you and the client, not the complete set of hidden inputs.
  •  Simpler programming. You don't have to make sure you included your hidden inputs in every single one of your pages.
  •  Security. The client can alter the contents of hidden inputs however he pleases. You can't easily pass sensible information via hidden inputs, you need to encrypt it. Session values are stored on the server, so the client doesn't have access to them.

Thanks & Regards,