Sharepoint母版页和会话状态 [英] Sharepoint Master Pages and Session State

查看:82
本文介绍了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());
        }
    }

}

在浏览器中加载此页面时,出现以下错误

对象引用未设置为对象的实例.

但是,如果我切换到开箱即用的母版页(例如,Black Vertical),则代码有效!我得到了本先生{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 Designer中打开OOTB主页,然后单击保存"按钮,它将自定义"该页面.一旦这样做,我的代码就会停止工作,如果我然后将母版页面重置回站点定义,我的代码将再次开始工作!

我有一个解决文件,是任何想要安装此文件以查看其行为的人.

解决方案

我想我找到了原因,看来,如果将自定义母版页包装在解决方案中,则不会(大多数情况下)出现此问题. /p>

这是一篇文章,列出了问题和可能的解决方法

https://stackoverflow.com/questions/981836 /perform-find-and-place-in-visual-studio-build-events

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.

解决方案

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

这篇关于Sharepoint母版页和会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆