• Controlling Session Behavior in Asp.Net MVC4


    Posted By : Shailendra Chauhan, 06 Jan 2013 

    Updated On : 11 Jun 2014

     By default, Asp.Net MVC support session state. Session is used to store data values across requests. Whether you store some data values with in the session or not Asp.Net MVC must manage the session state for all the controllers in your application that is time consuming. Since, session is stored on server side and consumes server memory, hence it also affect your application performance.

    Session Less Controller

    If some of the controllers of your Asp.Net MVC application are not using session state features, you can disable session for those controller and can gain slight performance improvement of your application. You can simplify session state for your application by using available options for session state.

    In Asp.Net MVC4, SessionState attribute provides you more control over the behavior of session-state by specifying the value of SessionStateBehavior enumeration as shown below:

    SessionStateBehavior Enumeration's Value
    Value
    Description
    Default
    The default Asp.Net behavior is used to determine the session state behavior.
    Disabled
    Session state is disabled entirely.
    ReadOnly
    Read-only session state behavior is enabled.
    Required
    Full read-write session state behavior is enabled.

    In Asp.Net MVC, TempData use session state for storing the data values across requests. Hence, when you will disabled the session state for the controller, it will throw the exception as shown below:

    What do you think?

    I hope you will enjoy the tips while programming with Asp.Net MVC. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

  • 相关阅读:
    Exchange ProxyLogon漏洞分析
    Java安全之Dubbo反序列化漏洞分析
    c# 基础语法
    Java安全之Axis漏洞分析
    c# 反射调用
    Exchange CVE20200688代码执行漏洞分析
    Windows上使用pm2运行Net Core项目
    重新点亮shell————测试命令[六]
    重新点亮shell————sed其他命令[十一]
    重新点亮shell————awk 控制语句[十三]
  • 原文地址:https://www.cnblogs.com/imust2008/p/5338633.html
Copyright © 2020-2023  润新知