Alert.update()在sharepoint中拒绝访问?

时间:2011-05-14 18:38:09

标签: sharepoint sharepoint-2007 wss

我正在尝试使用编程为登录用户添加警报。它正在提供“拒绝访问”。 我在SPSecurity.RunWithElevatedPrivileges(delegate()下运行此代码。我检查了所有地方的应用程序池身份权限。他在Farm Admin组,Site collection group和数据库所有者组中。仍然得到同样的错误。为什么会这样?

protected void ChkBx41_CheckedChanged(object sender, EventArgs e)
{
    SPUser user = SPContext.Current.Web.CurrentUser;
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPWeb eweb = new SPSite(url.Text).OpenWeb())
        {
            SPUser juser = null;
            eweb.AllowUnsafeUpdates = true;
            try
            {
                juser = eweb.AssociatedMemberGroup.Users[user.LoginName];
            }
            catch (Exception)
            {
            }
            if (ChkBx41.Checked)
            {
                if (juser == null)
                {
                  eweb.AssociatedMemberGroup.AddUser(eweb.EnsureUser(user.LoginName));
                  createalert(SPAlertFrequency.Daily, eweb, eweb.EnsureUser(user.LoginName),true);
                }
                RBList4.SelectedValue = "Daily";
                RBList4.Enabled = true;
            }
            else
            {
                if (juser != null)
                {
                    eweb.AssociatedMemberGroup.RemoveUser(juser);
                    removealert(eweb, juser);
                    RBList4.SelectedValue = null;
                    RBList4.Enabled = false;
                }
            }

        }
    });
}
public void createalert(SPAlertFrequency frq, SPWeb pweb, SPUser puser,bool mail)
    {
        try
        {
            pweb.AllowUnsafeUpdates = true;
            foreach (SPList lst in pweb.Lists)
            {
                if (lst.BaseTemplate == SPListTemplateType.Announcements || lst.BaseTemplate == SPListTemplateType.DiscussionBoard || lst.BaseTemplate == SPListTemplateType.Events )
                {
                    SPAlert alt = puser.Alerts.Add();
                    alt.AlertType = SPAlertType.List;
                    alt.List = lst;
                    alt.EventType = SPEventType.All;
                    alt.AlertFrequency = frq;
                    alt.Title = "SPE " + lst.Title;
                    if (frq != SPAlertFrequency.Immediate)
                    {
                        alt.AlertTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 15, 0, 0);
                    }
                    if (mail)
                    {                            
                        alt.Update(); // Access denied exception
                    }
                    else
                    {
                        alt.Update(false); 
                    }
                }
              }
            }
            pweb.AllowUnsafeUpdates = false;
        }
        catch (Exception ee) {
            throw ee.Message;
        }
        pweb.Dispose();
    }

1 个答案:

答案 0 :(得分:0)

我不知道这是否是解决方案。你可以在继续之前更新eweb(创建/删除警报)

eweb.AssociatedMemberGroup.AddUser(eweb.EnsureUser(user.LoginName));
eweb.AssociatedMemberGroup.Update();
eweb.update();