views:

300

answers:

2

In ASP.NET, I would like to disable session state from master page, however @Master directive doesn't have EnableSessionState attribute as @Page does. Is there any workaround?

+2  A: 

EnableSessionState needs to be done at a page level - as your masterpage will be used on many pages.

Do you want turn off session across the whole site? In your web.config you can do this:

<sessionState  mode="off" />

http://msdn.microsoft.com/en-us/library/h6bb9cz9.aspx

russau
niaher
I haven't tested the difference - but i'd guess it's a negligible improvment.
russau
+2  A: 

To continue where russau left off, if you need to be able to configure only a subset of pages, then you could use locational configuration to do it. You would need to put the pages that need to have session state turned off in a common location, then use the following (where path is ~/nosessionstate/):

<location path="nosessionstate">
    <system.web>
        <sessionState mode="Off" />
    </system.web>
</location>

If you are unable to group all of the pages together in a single location, you could have multiple location elements for each path. However, if your pages must be grouped with other pages that do need session state, then your only option is to configure it on a per-page basis.

jrista