Disable Session State in Code Behind?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coconet

    Disable Session State in Code Behind?

    Using ASP.NET 2.0, I want to use the code-behind to disable session
    state (eg I do not want to put anything in the .aspx page template). I
    also do not want to touch web.config.

    How can I do this?

    Thanks.


  • Juan T. Llibre

    #2
    Re: Disable Session State in Code Behind?

    Set Page.EnableSess ionstate="false " in the code-behind.




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    =============== =============== ========
    "coconet" <coconet@commun ity.nospamwrote in message news:drgc749neq 31fvg9tkf2jb89m uac9buosp@4ax.c om...
    Using ASP.NET 2.0, I want to use the code-behind to disable session
    state (eg I do not want to put anything in the .aspx page template). I
    also do not want to touch web.config.
    >
    How can I do this?
    >
    Thanks.
    >
    >

    Comment

    • Patrice

      #3
      Re: Disable Session State in Code Behind?

      You mean doing the same than with the EnableSessionSt ate page directive ?

      IMO you can't from the page code-behind as your page is already running and
      so ASP.NET needed already to know wether session should be activated or not
      for this page... This might be possible using a ( stop !!).

      Gave a look and found :


      It looks to be done at compile time by using or not the
      IRequiresSessio nState, IReadOnlySessio nState interfaces so you could declare
      this from your code behind. I tried, it works.

      Strickly speaking you can't do this without touching web.config as it
      doesn't seem you can tell that session is not required at all (likely the
      "false" value allows to suppress the addition of those interfaces but you
      have no way to do that if session are already enabled in the web config as
      the absence of the directive will cause the appropriate interface to be
      added for you).

      So the best you could do for now would be :
      - to suppress session in the web.config
      - you can add session support by using IRequiresSessio nState or
      IReadOnlySessio nState in your code behind file

      You may want still to elaborate about what you are trying to do and why the
      page directive doesn't fit...

      --
      Patrice

      "coconet" <coconet@commun ity.nospama écrit dans le message de groupe de
      discussion : drgc749neq31fvg 9tkf2jb89muac9b uosp@4ax.com...
      Using ASP.NET 2.0, I want to use the code-behind to disable session
      state (eg I do not want to put anything in the .aspx page template). I
      also do not want to touch web.config.
      >
      How can I do this?
      >
      Thanks.
      >
      >

      Comment

      • coconet

        #4
        Re: Disable Session State in Code Behind?


        Thanks for the help. I wanted to avoid touching the .aspx to keep all
        changes, etc in a unit-testable .cs file. I'll just live with it in
        the .aspx for now.

        Thanks.


        On Thu, 10 Jul 2008 19:46:41 +0200, "Patrice"
        <http://www.chez.com/scribe/wrote:
        >You mean doing the same than with the EnableSessionSt ate page directive ?
        >
        >IMO you can't from the page code-behind as your page is already running and
        >so ASP.NET needed already to know wether session should be activated or not
        >for this page... This might be possible using a ( stop !!).
        >
        >Gave a look and found :
        >http://www.15seconds.com/issue/020417.htm
        >
        >It looks to be done at compile time by using or not the
        >IRequiresSessi onState, IReadOnlySessio nState interfaces so you could declare
        >this from your code behind. I tried, it works.
        >
        >Strickly speaking you can't do this without touching web.config as it
        >doesn't seem you can tell that session is not required at all (likely the
        >"false" value allows to suppress the addition of those interfaces but you
        >have no way to do that if session are already enabled in the web config as
        >the absence of the directive will cause the appropriate interface to be
        >added for you).
        >
        >So the best you could do for now would be :
        >- to suppress session in the web.config
        >- you can add session support by using IRequiresSessio nState or
        >IReadOnlySessi onState in your code behind file
        >
        >You may want still to elaborate about what you are trying to do and why the
        >page directive doesn't fit...

        Comment

        • George

          #5
          Re: Disable Session State in Code Behind?

          I am not sure at which stage you can set Page.EnableSess ionstate="false "
          (for it to make sense)
          I have a feeling that you can do that only in constructor to work....

          Obviously on Render even it will be too late to do that. Because the Session
          module already kicked in...
          If someone has some clarification on that it would be good.

          George.

          "Juan T. Llibre" <nomailreplies@ nowhere.comwrot e in message
          news:OEgEsQr4IH A.4272@TK2MSFTN GP03.phx.gbl...
          Set Page.EnableSess ionstate="false " in the code-behind.
          >
          >
          >
          >
          Juan T. Llibre, asp.net MVP
          asp.net faq : http://asp.net.do/faq/
          foros de asp.net, en español : http://asp.net.do/foros/
          =============== =============== ========
          "coconet" <coconet@commun ity.nospamwrote in message
          news:drgc749neq 31fvg9tkf2jb89m uac9buosp@4ax.c om...
          >Using ASP.NET 2.0, I want to use the code-behind to disable session
          >state (eg I do not want to put anything in the .aspx page template). I
          >also do not want to touch web.config.
          >>
          >How can I do this?
          >>
          >Thanks.
          >>
          >>
          >
          >

          Comment

          • Juan T. Llibre

            #6
            Re: Disable Session State in Code Behind?

            re:
            !IMO you can't from the page code-behind as your page is already running

            Wouldn't this code, in Page_Init, do the trick ?

            pagesSection.En ableSessionStat e = PagesEnableSess ionState.False




            Juan T. Llibre, asp.net MVP
            asp.net faq : http://asp.net.do/faq/
            foros de asp.net, en español : http://asp.net.do/foros/
            =============== =============== ========
            "Patrice" <http://www.chez.com/scribe/wrote in message news:1E62E14D-8CAE-4958-85F0-539624D61772@mi crosoft.com...
            You mean doing the same than with the EnableSessionSt ate page directive ?
            >
            IMO you can't from the page code-behind as your page is already running and so ASP.NET needed already to know wether
            session should be activated or not for this page... This might be possible using a ( stop !!).
            >
            Gave a look and found :

            >
            It looks to be done at compile time by using or not the IRequiresSessio nState, IReadOnlySessio nState interfaces so you
            could declare this from your code behind. I tried, it works.
            >
            Strickly speaking you can't do this without touching web.config as it doesn't seem you can tell that session is not
            required at all (likely the "false" value allows to suppress the addition of those interfaces but you have no way to
            do that if session are already enabled in the web config as the absence of the directive will cause the appropriate
            interface to be added for you).
            >
            So the best you could do for now would be :
            - to suppress session in the web.config
            - you can add session support by using IRequiresSessio nState or IReadOnlySessio nState in your code behind file
            >
            You may want still to elaborate about what you are trying to do and why the page directive doesn't fit...
            >
            --
            Patrice
            >
            "coconet" <coconet@commun ity.nospama écrit dans le message de groupe de discussion :
            drgc749neq31fvg 9tkf2jb89muac9b uosp@4ax.com...
            >Using ASP.NET 2.0, I want to use the code-behind to disable session
            >state (eg I do not want to put anything in the .aspx page template). I
            >also do not want to touch web.config.
            >>
            >How can I do this?
            >>
            >Thanks.
            >>
            >>
            >

            Comment

            • Juan T. Llibre

              #7
              Re: Disable Session State in Code Behind?

              re:
              !I have a feeling that you can do that only in constructor to work....

              I *know* that in the constructor you can't do it.
              I haven't tested, but it would seem to me that in Page_Init it should work.

              I'll try to set up a test scenario to test this.




              Juan T. Llibre, asp.net MVP
              asp.net faq : http://asp.net.do/faq/
              foros de asp.net, en español : http://asp.net.do/foros/
              =============== =============== ========
              "George" <noemail@comcas t.netwrote in message news:eI3U6xr4IH A.2072@TK2MSFTN GP04.phx.gbl...
              >I am not sure at which stage you can set Page.EnableSess ionstate="false " (for it to make sense)
              I have a feeling that you can do that only in constructor to work....
              >
              Obviously on Render even it will be too late to do that. Because the Session module already kicked in...
              If someone has some clarification on that it would be good.
              >
              George.
              >
              "Juan T. Llibre" <nomailreplies@ nowhere.comwrot e in message news:OEgEsQr4IH A.4272@TK2MSFTN GP03.phx.gbl...
              >Set Page.EnableSess ionstate="false " in the code-behind.
              >>
              >>
              >>
              >>
              >Juan T. Llibre, asp.net MVP
              >asp.net faq : http://asp.net.do/faq/
              >foros de asp.net, en español : http://asp.net.do/foros/
              >============== =============== =========
              >"coconet" <coconet@commun ity.nospamwrote in message news:drgc749neq 31fvg9tkf2jb89m uac9buosp@4ax.c om...
              >>Using ASP.NET 2.0, I want to use the code-behind to disable session
              >>state (eg I do not want to put anything in the .aspx page template). I
              >>also do not want to touch web.config.
              >>>
              >>How can I do this?
              >>>
              >>Thanks.
              >>>
              >>>
              >>
              >>
              >

              Comment

              Working...