I have created a Visual Web Part. Inside, there is submit button that on click runs some code. It works fine with my Site Collection Administrator. but it doesn't work with my test user. This test user has read permissions only on the site.
When I click on the Visual Web Part button I get:
"Sorry this site is not shared with you”
are there any permission I need to set to enable a user to submit from a visual web part?
Edit: On click method:
protected void btninvia_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite spsite = SPContext.Current.Site;
SPWeb spweb = spsite.RootWeb;
... code that works ....
SPListItem item = addMissione(user.User); // this method causes the authorization problem
... not executed code
});
}
addMission method:
private SPListItem addMissione(SPUser spuser)
{
SPListItem item =null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
Logger.WriteLog(Logger.Category.Information, "addMissione", "spuser" + spuser.LoginName);
SPSite spsite = SPContext.Current.Site;
SPWeb spweb = spsite.RootWeb;
SPList splist = spweb.Lists["Missions"];
item = splist.AddItem();
item["Field1"] = spuser;
item["Field2"] = Field2.Text;
item["Start Date"] = startdate.SelectedDate;
....
item.Update();
Logger.WriteLog(Logger.Category.Information, "addMission", "item update"); // this code is not run
...
Logger.WriteLog(Logger.Category.Information, "addMissione", "fine addMissione");
});
return item;
}