尝试更新用户的警报时“访问被拒绝”

时间:2010-11-24 11:46:07

标签: sharepoint sharepoint-2007

我在尝试更新团队讨论列表中的用户警报时收到此错误。 我的代码是:

    SPUser user = mysite.OpenWeb().CurrentUser;

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        SPSite site = new SPSite(mysite.ID);
        SPWeb myweb = site.OpenWeb();

        string id = this.Page.Request.QueryString["RootFolder"].ToString();
        string[] rootfolder = id.Split(@"//".ToCharArray());
        myweb.AllowUnsafeUpdates = true;
        SPList mylsit = myweb.Lists["Team Discussion"];


        SPListItem item = mylsit.GetItemById(21);


        SPUser curruser = myweb.EnsureUser(user.LoginName);
        Response.Write(curruser.LoginName);

        SPAlert newAlert = user.Alerts.Add();
        newAlert.AlertType = SPAlertType.Item;

        newAlert.Item = item;

        newAlert.Properties["eventtypeindex"] = "1";

        newAlert.AlertFrequency = SPAlertFrequency.Immediate;

        newAlert.Update(false);

        myweb.AllowUnsafeUpdates = false;
    });

我正在执行alert.update()时收到错误。请帮帮我

1 个答案:

答案 0 :(得分:1)

我唯一能注意到的是RunWithElevatedPrivileges函数下面的MSDN文章中的“!Important”部分:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

看起来你正在做某种形式的写作,可能没有调用ValidateFormDigest?