C# 在 SharePoint 2010 中启用会话状态?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2237989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enabling Session State in SharePoint 2010?
提问by Steve Danner
I have a web service built for SharePoint 2007 that I am trying to port to SharePoint 2010. This web service is dependent on session state to function properly, but so far, I have been enable to get session state to work at all in SharePoint 2010. This web service runs as its own web application under t
he /_vti_bin
virtual directory. I have tried all of the following with no luck:
我有一个为 SharePoint 2007 构建的 Web 服务,我正尝试将其移植到 SharePoint 2010。此 Web 服务依赖于会话状态才能正常运行,但到目前为止,我已经能够让会话状态在 SharePoint 2010 中工作. 此 Web 服务在/_vti_bin
虚拟目录下作为自己的 Web 应用程序运行。我已经尝试了以下所有方法,但都没有运气:
- Ensured the "State Service" service application is running.
- Added the
System.Web.SessionState.SessionStateModule
http module to my application's web.config file. - Added the
System.Web.SessionState.SessionStateModule
http module to my SharePoint root web.config file. - Added
<pages enableSessionState="true" />
to my application's web.config file. - Added
<pages enableSessionState="true" />
to my root web.config file.
- 确保“状态服务”服务应用程序正在运行。
- 将
System.Web.SessionState.SessionStateModule
http 模块添加到我的应用程序的 web.config 文件中。 - 将
System.Web.SessionState.SessionStateModule
http 模块添加到我的 SharePoint 根 web.config 文件中。 - 添加
<pages enableSessionState="true" />
到我的应用程序的 web.config 文件中。 - 添加
<pages enableSessionState="true" />
到我的根 web.config 文件中。
Additional Environment info:
附加环境信息:
- Visual Studio 2008 - SP1
- .NET 3.5 - SP1
- SharePoint 2010 - RC
- Windows Server 2008 R2
- ASMX web service (not WCF)
- Visual Studio 2008 - SP1
- .NET 3.5 - SP1
- SharePoint 2010 - RC
- 视窗服务器 2008 R2
- ASMX Web 服务(不是 WCF)
Had anyone had any luck getting a web application orweb service to use session state in SharePoint 2010 yet?
有没有人有幸让 Web 应用程序或Web 服务在 SharePoint 2010 中使用会话状态?
Thanks!
谢谢!
Steve
史蒂夫
采纳答案by Joshua
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.
然后,您必须进入您的 Web 应用程序并将相同的会话状态模块添加到 IIS7 托管管道。
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
打开 IIS 7 管理器,然后找到您的 Web 应用程序。
双击 IIS 部分中的“模块”。
单击右侧窗格中的“添加托管模块...”。
在 Add Managed Module 对话框中,输入名称
"SessionState"
或类似名称,然后从下拉列表中选择以下项目: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!
之后,应该为您的网络应用程序/网络服务启用会话状态!
回答by anonymous
Joshua's solution helped point me in the right direction but I had to make some variations for my scenario - an ASP.NET 3.5 Web Site deployed to the _layouts folder.
Joshua 的解决方案帮助我指明了正确的方向,但我不得不为我的场景做一些改变——一个部署到 _layouts 文件夹的 ASP.NET 3.5 网站。
Here are the steps that worked for me:
以下是对我有用的步骤:
changed the
<pages>
tag in the web.config for the Web Site to<pages enableSessionState="true" />
Added the System.Web.SessionState.SessionStateModulemodule at the Sharepoint website level (not the entire IIS level - that'll break the Central Administration, I tried :( ) as per @Joshua's solution. If you're deploying a Web Application instead of a Web Site, you'll want to add it at your Web Application level.
将
<pages>
网站的 web.config 中的标记更改为<pages enableSessionState="true" />
在 Sharepoint 网站级别添加了System.Web.SessionState.SessionStateModule模块(不是整个 IIS 级别 - 这会破坏中央管理,我尝试 :( )按照@Joshua 的解决方案。如果您要部署 Web 应用程序的网站,您需要在您的 Web 应用程序级别添加它。
Adding the SessionState HTTPModule below to the web.config didn't seem to have an effect for me, probably because I was riding on Sharepoint's web.config as my project was a Web Site and not a Web Application. Not too clear on this issue.
将下面的 SessionState HTTPModule 添加到 web.config 似乎对我没有影响,可能是因为我使用的是 Sharepoint 的 web.config,因为我的项目是网站而不是 Web 应用程序。这个问题不是很清楚。
<httpModules>
<add name = "Session" type = "System.Web.SessionState.SessionStateModule" />
</httpModules>
回答by carol
Do like below:
像下面这样:
<modules runAllManagedModulesForAllrequests>
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</modules>
modules is an xml tag. I don't know why, this post is not taking xml tags..
modules 是一个 xml 标签。我不知道为什么,这篇文章没有使用 xml 标签..
Thanks
谢谢
Carol
颂歌
回答by Dave Milner
You may need to turn on the Session State Service. Use the PowerShell cmdlet Enable-SPSessionStateService. This will create a Session State database and start the service in SharePoint 2010.
您可能需要打开会话状态服务。使用 PowerShell cmdlet Enable-SPSessionStateService。这将创建一个会话状态数据库并在 SharePoint 2010 中启动该服务。
Reference information: http://technet.microsoft.com/en-us/library/ee890113.aspx
参考资料:http: //technet.microsoft.com/en-us/library/ee890113.aspx
回答by Kirk Liemohn
The best link I have seen on this is here: http://blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx
我见过的最好的链接在这里:http: //blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx