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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top