Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Anonymous users unable to create list items

$
0
0

Hi,

I have enabled anonymous access at the webapplication from the authentication providers through CA, provided full access to anonymous users at site collection level. I am using the below code to allow anon users to submit a query.

if (Page.IsValid)
            {
                SPUserToken sysToken = SPContext.Current.Site.SystemAccount.UserToken;
                using (var systemSite = new SPSite(SPContext.Current.Site.ID, sysToken))
                {
                    using (var sysWeb = systemSite.OpenWeb(SPContext.Current.Web.ID))
                    {
                        try
                        {
                            sysWeb.AllowUnsafeUpdates = true;
                            SPList list = sysWeb.Lists["InformationRequest"];

                            SPQuery qry = new SPQuery();
                            qry.Query = string.Concat("<Where><Eq>",
                                                              "<FieldRef Name='Title' />",
                                                              "<Value Type='Counter'>0</Value>",
                                                              "</Eq></Where>");
                            SPListItemCollection items = list.GetItems(qry);
                            SPListItem item = items.Add();
                            item["FirstName"] = this.fname.Text.Trim();
                            item["LastName"] = lname.Text.Trim();
                            item["EmailAddress"] = email.Text.Trim();
                            item["Comment"] = comment.Text.Trim();
                            item["PageLink"] = pageLink.Text.Trim();

                            item.Update();
                            Response.Redirect("/pages/thankyou.aspx?page=requestinformation");
                        }
                        finally
                        {
                            sysWeb.AllowUnsafeUpdates = false;
                        }
                    }

when I access the site as an authenticated users it all works fine, site prompts for credentials for anon users. since this will be a internet site I don't want to disable viewformpageslockdown feature. Have tried by configuriing unique permisson on the list in questions and granting add permission to anonymous users still it doesn't work how ever the whole of using system account and unsafeupdates is to avoid configuring permissions at list level and allow anonymous users execute code as system account. Any suggestion in fixing this issue pls? I could have gone down with elevated privilages but thought this was clean how ever this doesn't work :(

Regards,



san


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>