Sharepoint 母版页和会话状态
我正在使用 Heather Solomon 的最小发布母版页,我有一个简单的功能,其中包含 apsx 页面和一个执行此操作的代码隐藏文件
public class SSInformPage : Page
{
protected Literal Literal1;
protected override void OnLoad(EventArgs e)
{
//base.OnLoad(e);
try
{
HttpContext.Current.Session["Name"] = "Mr Ben";
Literal1.Text = string.Format("{0} {1}", HttpContext.Current.Session["Name"].ToString(), Session.SessionID);
}
catch (Exception ex)
{
Literal1.Text = string.Format(ex.Message.ToString());
}
}
}
当此页面在浏览器中加载时,我收到以下错误
对象引用未设置为对象的实例。
但是,如果我切换到开箱即用的母版页(例如黑色垂直),代码就可以工作! 我得到了“Mr Ben {session ID}”的预期输出,
我什至创建了一个新的空白母版页,并将黑色垂直母版页的全部内容复制到其中。 我将站点设置为这个新的母版页,加载页面并期望一切正常,但收到“对象引用...”错误。 这是如何运作的? 这是完全相同的母版页,但代码仅在 OOTB 版本时才有效。
我已在中央管理中启用会话状态,web.config 文件和程序集已部署到 GAC。
更新 从另一个论坛上的建议来看,这似乎是一个信任问题,我错误地认为解决方案部署到 GAC,它实际上部署到 Bin 文件夹。 我尝试重置此设置,但似乎无法让 WSPBuilder 部署到 GAC 的解决方案,尽管我已设法让它停止部署到 Web 应用程序的 bin 文件夹。
有谁知道如何获得部署到 GAC 文件夹的解决方案? 这是我的 stsadm 命令
stsadm -o deploysolution -name Test.SessionState.Solution.wsp -immediate -url http://example -allowGacDeployment -allowCasPolicies -force
Udpate 2 不,这不是信任问题,我重新创建了我的解决方案并确保它部署到 GAC。 如果我在 sharepoint 设计器中打开 OOTB 母版页并单击“保存”按钮,它将“自定义”页面。 一旦我这样做,我的代码就会停止工作,如果我将母版页重置回站点定义,我的代码将再次开始工作!
我有一个解决方案文件,任何人都想安装它来查看其行为。
I’m using Heather Solomon’s minimal publishing master page, I’ve got a simple feature with an apsx page and a code behind file that does this
public class SSInformPage : Page
{
protected Literal Literal1;
protected override void OnLoad(EventArgs e)
{
//base.OnLoad(e);
try
{
HttpContext.Current.Session["Name"] = "Mr Ben";
Literal1.Text = string.Format("{0} {1}", HttpContext.Current.Session["Name"].ToString(), Session.SessionID);
}
catch (Exception ex)
{
Literal1.Text = string.Format(ex.Message.ToString());
}
}
}
When this page loads in the browser I get the following error
Object reference not set to an instance of an object.
Yet if I switch to an out of the box master page (e.g. Black Vertical) the code works! I get the expected output of “Mr Ben {session ID}”
I’ve even created a new blank master page and copied the entire contents of the Black Vertical master page into it. I set the site to this new master page, I load the page expecting everything to work and receive the ‘Object reference…’ error. How does that work? It’s exactly the same master page yet the code only works if it’s an OOTB version.
I've enabled session state in central admin, the web.config file and the assembly is deployed to the GAC.
Update
From a suggestion on another forum it seems to be a trust issue, i was mistaken in thinking the solution deploys to the GAC, it was actually deploying to the Bin folder. I've tried to reset this but can't seem to get WSPBuilder to deploy to the solution to the GAC, although i've managed to get it to stop deploying to the web application's bin folder.
Does anyone know how to get a soltution to deploy to the GAC folder? this is my stsadm command
stsadm -o deploysolution -name Test.SessionState.Solution.wsp -immediate -url http://example -allowGacDeployment -allowCasPolicies -force
Udpate 2
No it's not a trust issue, I re-created my solution and ensures it deploys to the GAC. If I open a OOTB master page in sharepoint designer and click the save button it's will 'customise' the page. As soon as I do this my code stops working, if I then reset the master page back to the site definition my code starts working again!
I have a soltion file is anyone want to install this to see the behaviour.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我找到了原因,似乎如果自定义母版页包含在解决方案中,则不会出现此问题(大多数情况下)。
这是一篇文章,列出了该问题和可能的解决方法
https:// stackoverflow.com/questions/981836/perform-find-and-replace-in-visual-studio-build-events
I think i found the reason, it seems if a custom master page is wrapped in a solution this problem doesn't occur (most of the time).
Here's an article listing the issue and possible work arounds
https://stackoverflow.com/questions/981836/perform-find-and-replace-in-visual-studio-build-events
我无法帮助解决您的具体错误,Heather 的母版页应该可以正常工作,但是我担心您提到在 web.config 文件中启用会话状态。 正确的位置是在 SharePoint 管理中心,使用此处的说明。
这是因为 SharePoint 提供了自己的会话管理器,因为会话必须在多个 WFE 之间共享。 如果您确实想以标准 ASP.NET 方式执行此操作,请使用 埃里克·克劳斯的说明。 但不确定这是如何支持的或者它会导致什么副作用。
尝试其中一种替代方案,并让我们知道效果如何。 希望错误消失!
I can't help with your specific error and Heather's master page should work fine, however I'm concerned that you mention enabling session state in the web.config file. The correct place is in SharePoint Central Administration using the instructions here.
This is because SharePoint provides its own session manager as session has to be shared across multiple WFEs. If you really want to do this the standard ASP.NET way, use Eric Kraus' instructions. Not sure how supported this is however or what side effects it causes.
Try one of these alternatives and let us know how it goes. Hopefully the error goes away!