Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:15:15+00:00 2026-05-22T02:15:15+00:00

I am trying to add alert for loging user using programming. It is giving

  • 0

I am trying to add alert for loging user using programming. It is giving “Access denied”.
I am running this code in under SPSecurity.RunWithElevatedPrivileges(delegate(). I checked application pool identity rights in all places. He is in Farm Admin group, Site collection group and database owner group. Still getting same error. Why this happening?

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:15:16+00:00Added an answer on May 22, 2026 at 2:15 am

    I don’t know if this is the solution. Can you please update eweb before moving ahead(Create/Delete Alert)

    eweb.AssociatedMemberGroup.AddUser(eweb.EnsureUser(user.LoginName));
    eweb.AssociatedMemberGroup.Update();
    eweb.update();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add some functionality to our code base by using tied scalars.
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Trying to add a class object into a List using reflection, but when invoking
I'm using the jQuery validation plugin trying to add rules based on data- attributes.
I am trying to have a method in my code behind at runtime add
I am trying add on dimension of an array together into a variable using
I am trying to add and remove things in a string with using arrays.
i am trying to add and delete records(games) from my database using jquery and
I'm making Rails 3.1.1 app and trying to add some jQuery code to it.
I'm trying to add an alert dialog within a method, but I'm getting an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.