I have a SharePoint web application which contains two applications.
- Sp.test.com => SharePoint web application, claims based authentication.
- Employees => Employees application, authentication with AD account. This application access to SharePoint using the object model with the logged-in user.
- Guests => Guests application, anonymous access. This application access to SharePoint using the object model with impersonation.
When access to SharePoint using the object model from Employees application, for example with user X, everything works correctly.
However, when access to SharePoint using the object model from Guest application, for example impersonating with user X, always get an access denied message.
Code used:
SPWeb webcon = null;
if (System.Web.HttpContext.Current != null)
webcon = SPControl.GetContextWeb(System.Web.HttpContext.Current);
try
{
int G_LCID = webcon.RegionalSettings.ServerLanguage.LCID;
}
catch (Exception ex)
{
// Error
}
The error occurs accessing the property webcon.RegionalSettings.ServerLanguage.LCID
The property webcon.CurrentUser is null.
Error in SharePoint log:
Unknown SPRequest error occurred. More information: 0x80070005
SPRequest.OpenWeb: UserPrincipalName=, AppPrincipalName= ,bstrUrl=https://sp.test.com/Guests/default.aspx
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)), StackTrace: at Microsoft.SharePoint.SPWeb.InitWeb() at Microsoft.SharePoint.SPWeb.get_RegionalSettings() at _Default.Page_Load(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.default_aspx.ProcessRequest(HttpContext context) at System.Web.HttpAppl...
Thanks in advance.