Microsoft Knowledge Base Email Alertz

KBAlertz.com: (837376) - Explains that the session variables cannot be set in the ASP.NET Web application when Windows SharePoint Services is installed.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 837376 - Last Review: September 26, 2007 - Revision: 1.12

Session state cannot be used in ASP.NET with Windows SharePoint Services

On This Page

SYMPTOMS

When you have Microsoft Windows SharePoint Services (WSS) installed on your computer and when you browse the page that is set with session variables in the Microsoft ASP.NET Web application, you may receive the following error message:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive

CAUSE

This problem may occur after you install WSS on a server that has Microsoft Visual Studio .NET 2003 installed. The WSS ISAPI filter handles all incoming URLs. When you browse one of the ASP.NET Web application virtual directories, the ISAPI filter does not locate the URL path of the folder.

For example, this problem may occur when you visit a URL that is similar to the following:
http://ServerName/WebApplication/WebForm1.aspx
In this example, the folder that is named WebApplication does not exist in the WSS database, and you cannot browse the folder.

WORKAROUND

To work around this problem, follow these steps.

Modify the Web.config file

Make the following modifications in the Web.config file of the Web application:
  • Clear the WSS ASP.NET handler, and then specify the default ASP.NET handler for all pages.
  • Set the trust level to Full to allow the ASP.NET Web application to run correctly.
  • Enable the session module.
  • Enable Session state for all the pages that are in the Web application.

Create an ASP.NET Web application

  1. Start Microsoft Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects, under Templates, click ASP.NET Web Application, and then click OK. By default, the WebForm1.aspx Web form is created.
  4. In Solution Explorer, right-click WebForm1.aspx, and then click View Code.
  5. Replace the existing code in the WebForm1.aspx.vb file with the following code:
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
    #Region " Web Form Designer Generated Code "
    
        'The Web Form Designer requires this call.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    
        End Sub
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    
        'NOTE: The Web Form Designer requires the following placeholder declaration.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Init
            'CODEGEN: The Web Form Designer requires this method call.
            'Do not modify it by using the Code editor.
            InitializeComponent()
        End Sub
    
    #End Region
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
            'Put user code to initialize the page here.
            Session.Add("Test", 1)
            Session.Add("Test1", 2)
            Session.Add("Test2", 3)
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
            Response.Redirect("WebForm2.aspx")
        End Sub
    End Class
    
  6. Switch to the Design view of the WebForm1.aspx Web form.
  7. On the View menu, click HTML Source.
  8. Replace the existing HTML source code for the WebForm1.aspx Web form with the following HTML code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" 
    Inherits="WebApplication5.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <title>WebForm1</title>
      <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
      <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
      <meta name="vs_defaultClientScript" content="JavaScript">
      <meta name="vs_targetSchema" 
    content="http://schemas.microsoft.com/intellisense/ie5">
     </HEAD>
      <body MS_POSITIONING="GridLayout">
       <form id="Form1" method="post" runat="server">
         <asp:Button id="Button1" style="Z-INDEX: 101; 
    LEFT: 8px; POSITION: absolute; TOP: 8px"  runat="server" Text="Button">
         </asp:Button>
      </form>
      </body>
    </HTML>
    
  9. Add another Web form to the existing project. To do this, follow these steps:
    1. On the File menu, click Add New Item.The Add New Item dialog box appears.
    2. In the Categories box, click Web Project Items, and then double-click Web Form in the Templates box. By default, a Web form that is named WebForm2.aspx is created.
  10. Replace the existing code in the WebForm2.aspx.vb file with the following code:
    Public Class WebForm2
        Inherits System.Web.UI.Page
    
    #Region " Web Form Designer Generated Code "
    
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    
        End Sub
    
        'NOTE: The Web Form Designer requires the following placeholder declaration.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Init
            'CODEGEN: The Web Form Designer requires this method call.
            'Do not modify it by using the Code editor.
            InitializeComponent()
        End Sub
    
    #End Region
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
            'Put user code to initialize the page here.
            Response.Write(Session("Test") & "<br>")
            Response.Write(Session("Test1") & "<br>")
            Response.Write(Session("Test2"))
          
        End Sub
    
    End Class
    
  11. Add the following directives in the Web.config file of the Web application between the <system.web> tag and the </system.web> tag:
    <!-- 
    Clear out the WSS ASP.NET handler and specify the default ASP.NET handler for all pages. 
    -->
    
    <httpHandlers>
    <clear />
    <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory, System.Web, 
    Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </httpHandlers>
    
    <!-- 
    Set the trust to Full. WSS configures a very restrictive trust policy that does not 
    allow ASP.NET Web application to run correctly.
    -->
    
    <trust level="Full" originUrl="" />
    
    <!-- 
    Enable the session module. This can also be enabled on the WSS Web.config, 
    but is not enabled by default. If you receive the following message:
    Parser Error Message: The module 'Session' is already in the application 
    and cannot be added again. You can remove the following 
    <httpModules></httpModules> section as session is already enabled 
    on the virtual server. 
    --> 
    
    <httpModules>
    <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
    </httpModules> 
    
    <!-- Enable session state for all the pages in the Web application. --> 
    <pages enableSessionState="true" enableViewState="true" 
    enableViewStateMac="true" validateRequest="false" />
    
  12. Save the modified Web.config file.
  13. Exclude the WebApplication folder by using SharePoint Central Administration. To do this, follow these steps:
    1. On the server that is running WSS, click Start, click Administrative Tools, and then click SharePoint Central Administration.
    2. In the Virtual Server Configuration area, click Configure virtual server settings.
    3. In the Virtual Server List list, click the virtual server that you must add the excluded paths to.
    4. Under Virtual Server Management, click Define managed paths.
    5. In the Add a New Path section, type the path that you want to exclude in the Path box.
    6. Click Excluded Path, and then click OK.
After you set these settings in the Web.config file of your Web application, you can browse the Web application, and then use the sessions in your Web pages.

STATUS

This behavior is by design.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
http://technet.microsoft.com/windowsserver/sharepoint/bb848085.aspx (http://technet.microsoft.com/windowsserver/sharepoint/bb848085.aspx)

http://technet.microsoft.com/windowsserver/sharepoint/default.aspx (http://technet.microsoft.com/windowsserver/sharepoint/default.aspx)

http://msdn2.microsoft.com/en-us/library/aa719558(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa719558(VS.71).aspx)

http://msdn2.microsoft.com/en-us/library/ms972429.aspx (http://msdn2.microsoft.com/en-us/library/ms972429.aspx)

APPLIES TO
  • Microsoft Windows SharePoint Services 2.0
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Academic Edition
Keywords: 
kbsetup kbaspnet kbstate kbconfig kbprb KB837376
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please