Make session readonly on asp.net programmatically (EnableSessionState=“ReadOnly”)

前端 未结 2 1415
难免孤独
难免孤独 2020-12-19 06:59

I need to make the session readonly so I can establish multiple requests to a page that uses sessions variables but in the readonly mode.

Since all the process are p

相关标签:
2条回答
  • 2020-12-19 07:17

    If you use ASP.NET MVC, you can use the SessionStateAttribute class on the controller level.

    [SessionState(SessionStateBehavior.ReadOnly)]
    

    If you want to control the behavior on an action level, you can use this:

    https://www.c-sharpcorner.com/UploadFile/ff2f08/session-state-behavior-per-action-in-Asp-Net-mvc/

    If you use ASP.NET Web Forms, I am not quite sure, but it should be something along these lines...

    0 讨论(0)
  • 2020-12-19 07:26

    In your scenario there must be one page who can write on session and other have no right to write on it. page that has session-state write access will hold a writer lock on the session until the request finishes. A page gains write access to the session state by setting the EnableSessionState attribute on the @Page directive to True. A page that has session-state read access for example, when the EnableSessionState attribute is set to ReadOnly, will hold a reader lock on the session until the request finishes.

    <% @Page EnableSessionState="ReadOnly" %>
    

    for more information you can read this link.

    0 讨论(0)
提交回复
热议问题