在sharepoint 2010中使用Session
先抄下来记着先http://blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx
SharePoint 2010 uses two services related to session state that have similar names but are separate and have different purposes.
- ASP.NET session state may be used on SharePoint 2010 pages. This service is automatically disabled in normal installations of SharePoint 2010; it may be enabled using the instructions below. Once enabled, it appears on the Service Applications page as “SharePoint Server ASP.NET Session State Service.”
- The State Service service application is designed for and only available to Office internal components such as InfoPath Forms Services and Visio Services. This service is automatically enabled in typical installations of SharePoint 2010 and is not related to ASP.NET session state. It appears on the Service Applications page as “State Service.”
To enable ASP.NET session state:
- Enter the following PowerShell command in the SharePoint 2010 Management Shell window:
Enable-SPSessionStateService –DefaultProvision
- On each web application for which you want to use session state, edit the web.config file and set the enableSessionState property of the pages element as follows:
<pages enableSessionState="true"
Guidelines for using SharePoint Server ASP.NET Session State:
- This session state may be used by custom code in web parts and other page-hosted controls.
- Session state information is stored in a configurable SQL database; this implies the following:
- Load-balancer affinity is not required.
- Heavy use of session state must be included in database/capacity planning. By default, the session state database is created on the same database server hosting the SharePoint 2010 farm configuration database. This can be changed to place it on another server; this can be done at a later date if necessary. To move it to another SQL server, it should first be disabled, then enabled again with different configuration that points to the other server.
- When enabled, Session state is available to the whole 2010 farm. Each web application can choose to enable it for use on ASP.NET pages (enableSessionState="true").
- Session state is partitioned using the root URL. This means that different web applications will have different session state objects; a web part can only access the session state object available to it. If host header site collections are used, then different session objects will be used for each site collection (the browser will have multiple session ids in different cookies).
Additional information about enabling session state:
Syntax 1 |
Syntax 2 |
Enable-SPSessionStateService |
Enable-SPSessionStateService |
Additional parameters are not discussed here; use Get-Help Enable-SPSessionStateService –full for more information.
The Enable-SPSessionStateService cmdlet creates a session state database, installs the ASP.NET session state schema, and updates the Web.config files on the farm to turn on the session state service.
If the DefaultProvision form of the command is used, all default settings are used. These are:
- DatabaseName = “SessionStateService_<GUID>”
- DatabaseServer = the same database server as the SharePoint 2010 configuration database
- DatabaseCredentials = Integrated Windows Authentication
If the DatabaseName form of the command is used, then these parameters may be set explicitly. If some of the parameters are not included, they default as above. To set specific credentials for accessing the session state database, note that this allows you to specify a SQL Authentication credential only, not a Windows credential. Then, use the Get-Credential command to create a PSCredential object from a username and password, then use that object as the argument of the DatabaseCredentials parameter.
After this service is enabled, “SharePoint Server ASP.NET Session State Service” will appear on the Service Applications management page.
You've already answered this yourself somewhere else on the interweb. :)
<httpModules>
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules>
THEN, you must go into your web application and add the same session state module to the IIS7 managed pipeline.
-
Open IIS 7 manager, and find your web application.
-
Double click "Modules" in the IIS section.
-
Click "Add Managed Module..." on the right hand pane.
-
In the Add Managed Module dialog, enter
"SessionState"
or something like that for the name, and choose the following item from the dropdown:System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
After that, session state should be enabled for your web app/web service!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构