Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sharepoint 2007中的HTTP模块和Cookie_C#_Asp.net_Sharepoint 2007_Httpmodule - Fatal编程技术网

C# Sharepoint 2007中的HTTP模块和Cookie

C# Sharepoint 2007中的HTTP模块和Cookie,c#,asp.net,sharepoint-2007,httpmodule,C#,Asp.net,Sharepoint 2007,Httpmodule,我有一些HTTP模块的概念验证代码。代码检查cookie是否存在,如果存在,则检索值,如果cookie不存在,则创建并设置值 完成后,我会在屏幕上写下,看看采取了什么行动(都很好,很简单)。因此,在第一个请求中创建cookie;后续请求从cookie中检索该值 当我在一个普通的asp.net网站上测试这一点时,一切都正常-耶!但是,一旦我将cookie传输到SharePoint,就会发生一些奇怪的事情,cookie永远不会保存—也就是说,无论页面刷新或二次请求如何,代码总是分支到创建cookie

我有一些HTTP模块的概念验证代码。代码检查cookie是否存在,如果存在,则检索值,如果cookie不存在,则创建并设置值

完成后,我会在屏幕上写下,看看采取了什么行动(都很好,很简单)。因此,在第一个请求中创建cookie;后续请求从cookie中检索该值

当我在一个普通的asp.net网站上测试这一点时,一切都正常-耶!但是,一旦我将cookie传输到SharePoint,就会发生一些奇怪的事情,cookie永远不会保存—也就是说,无论页面刷新或二次请求如何,代码总是分支到创建cookie中,而从不使用分支来检索值

这是密码

public class SwithcMasterPage : IHttpModule
{       

    public void Dispose()
    {
        throw new NotImplementedException();
    }

    public void Init(HttpApplication context)
    {
        // register handler
        context.PreRequestHandlerExecute += new EventHandler(PreRequestHandlerExecute);
    }

    void PreRequestHandlerExecute(object sender, EventArgs e)
    {
        string outputText = string.Empty;

        HttpCookie cookie = null;
        string cookieName = "MPSetting";

        cookie = HttpContext.Current.Request.Cookies[cookieName];
        if (cookie == null)
        {
            // cookie doesn't exist, create
            HttpCookie ck = new HttpCookie(cookieName);
            ck.Value = GetCorrectMasterPage();
            ck.Expires = DateTime.Now.AddMinutes(5);
            HttpContext.Current.Response.Cookies.Add(ck);

            outputText = "storing master page setting in cookie.";
        }
        else
        {
            // get the master page from cookie
            outputText = "retrieving master page setting from cookie.";
        }

        HttpContext.Current.Response.Write(outputText + "<br/>");
    }

    private string GetCorrectMasterPage()
    {
        // logic goes here to get the correct master page
        return "/_catalogs/masterpage/BlackBand.master";

    }
公共类SwithcMasterPage:IHttpModule
{       
公共空间处置()
{
抛出新的NotImplementedException();
}
公共void Init(HttpApplication上下文)
{
//寄存器处理程序
context.PreRequestHandlerExecute+=新事件处理程序(PreRequestHandlerExecute);
}
void PreRequestHandlerExecute(对象发送方,事件参数e)
{
string outputText=string.Empty;
HttpCookie=null;
字符串cookieName=“MPSetting”;
cookie=HttpContext.Current.Request.Cookies[cookieName];
if(cookie==null)
{
//cookie不存在,请创建
HttpCookie ck=新的HttpCookie(cookieName);
ck.Value=GetCorrectMasterPage();
ck.Expires=DateTime.Now.AddMinutes(5);
HttpContext.Current.Response.Cookies.Add(ck);
outputText=“将母版页设置存储在cookie中。”;
}
其他的
{
//从cookie获取母版页
outputText=“正在从cookie检索母版页设置。”;
}
HttpContext.Current.Response.Write(outputText+“
”); } 私有字符串GetCorrectMasterPage() { //逻辑在此获得正确的母版页 返回“/_目录/masterpage/BlackBand.master”; }
您可以使用Fiddler或FireBug(在FireFox上)检查响应以查看您的cookie是否已发送。如果未发送,则您可以在PostRequestHandlerExecute中尝试您的逻辑。这是假设Sharepoint或其他代码正在修补响应cookie。这样,您可以是最后一个添加cookie的人。

这是web应用程序的身份验证。到您必须使用已配置用于表单身份验证的FQDM