-3

I am trying to validate the group at the time of login, have used runwithelevated but still I get an error on "SPGroup managerGroup = Web.Groups["DevTest"];" That the page is not accessible. How can I get beyond this. If I run the same code once I'm logged in, this runs fine, but I'm trying to validate this at the time of login.

 SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;

    SPSecurity.RunWithElevatedPrivileges(delegate()                {
                        using (SPSite CurrentSite = new SPSite(site.ID))
                        { using (SPWeb CurrentWeb = CurrentSite.OpenWeb(web.ID))
                            {SPGroup managerGroup = Web.Groups["DevTest"];
                                bool isManager = CurrentWeb.IsCurrentUserMemberOfGroup(managerGroup.ID);

                                if (true)
                                {
                                    Response.Redirect("~/sitepages/createrequest.aspx");
                                }
                                else
                                {
                                    Label1.Text = "wrong user id or password";
                                }
                            }
                        }
Eric Alexander
  • 43,293
  • 10
  • 53
  • 93
Muskan
  • 886
  • 9
  • 30

2 Answers2

1

Shouldn't it be:

SPGroup managerGroup = CurrentWeb.Groups["DevTest"]; //not Web.Groups
Mike
  • 12,186
  • 8
  • 41
  • 64
1

I think the fix is

SPGroup managerGroup = CurrentWeb.Groups["DevTest"];

//You were using Web object which is out of the elevated context.

Amal Hashim
  • 28,306
  • 5
  • 31
  • 61