Using Session Objects with Session State Disabled Returns Type Mismatch Error

We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 7.0 running on Microsoft Windows Server 2008. IIS 7.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:For more information about IIS 7.0, visit the following Microsoft Web site:

Symptoms

When trying to use a session-level object or variable when session state is disabled, you may receive the following error message:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Session'
/scripts/sessiontest/test.asp, line XXX

Cause

This behavior is by design. The session object is not registered in the scripting name space, so any executing scripts do not understand it and return a "Type mismatch" error message.

More Information

The following steps will reproduce this behavior.

  1. Disable session state at the folder or site level:


    1. Select a Web site or folder in the Microsoft Management Console (MMC).
    2. Right-click the item and select Properties.
    3. Select the Directory or Home Directory tab.
    4. Click Configuration or Create, and then click Configuration.
    5. Select the App Options tab
    6. Clear the Enable Session State box.
    7. Click OK to return all the way back to the MMC.
    8. Create a page in the application's physical folder named Sesstest.asp with the following contents:
      <% Session("strTest") = "Some Text" %>
    9. Browse the page. You should see the error.
  2. Disable session state at the page level:


    1. Highlight a Web site or folder in the MMC.
    2. Right-click the item and select Properties.
    3. Select the Directory or Home Directory tab.
    4. Click Configuration or Create and then click Configuration.
    5. Select the App Options tab.
    6. Select the Enable Session State check box.
    7. Click OK to return all the way back to the MMC.
    8. Create a page in the application's physical folder named Sesstest.asp with the following contents:
      <% @EnableSessionState = False %>
      <% Session("strTest") = "Some Text" %>
    9. Browse to the page. You should see the error.
Properties

Article ID: 242425 - Last Review: Jul 30, 2008 - Revision: 1

Feedback