Frage

I'm making an ASMX web method call that contains the following code...It ultimately adds a new item to a sharepoint list

            string spsite = "http://site/subsite";


            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite objSite = new SPSite(spsite))
                {
                    using (SPWeb oweb = objSite.OpenWeb())
                    {
                        oweb.AllowUnsafeUpdates = true;
                        SPList list = oweb.Lists["List"];
                        SPListItem item = list.Items.Add();
                        item["col1"] = "test";
                        item["col2"] = "test";                                          

                        item.Update();

                    }
                }

            });

However, I get the following error messages...

You do not have permission to view this directory or page using the credentials that you supplied

Why is this? I thought RunWithElevatedPrivileges does away with this?

War es hilfreich?

Lösung

Where is this web service hosted? Using RunWithElevtatedPrivileges will use the account that the app pool runs on. If the app pool does not have permission, then you will get access denied.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top