vendredi 6 février 2015

Creating Web Application from Web Api Service - Access denied error



I have a method that creates a SPWebApplication and it works just fine from a console application, but when I put it in my Web API service I get "Access denied" error.


The web service uses the same application pool as the Sharepoint farm, which uses the farm administrator, so the code should run under farm administrator.


The problem is on this line newApplication = builder.Create();


Here is my method:



public static SPWebApplication CreateWebApplication(string tenantCode)
{
string hostHeader = tenantCode + ".domain.com";
string siteName = "SharePoint " + tenantCode;

SPWebApplicationBuilder builder = new SPWebApplicationBuilder(SPFarm.Local);
builder.Port = 443;
builder.HostHeader = hostHeader;
builder.ApplicationPoolId = siteName;
builder.IdentityType = IdentityType.SpecificUser;
builder.ApplicationPoolUsername = "domain\\sharepoint.content";
builder.ApplicationPoolPassword = CreateSecureString("pass");
builder.RootDirectory = new System.IO.DirectoryInfo("C:\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\" + tenantCode);
builder.CreateNewDatabase = true;
builder.DatabaseName = "WSS_Content_" + tenantCode;
builder.DatabaseServer = "SQL\\SHAREPOINT";
builder.UseNTLMExclusively = true;
builder.AllowAnonymousAccess = false;
builder.UseSecureSocketsLayer = true;

SPWebApplication newApplication;
newApplication = builder.Create();
newApplication.Provision();

return newApplication;
}


And here is the error from logs:



The SPPersistedObject, SPManagedAccount Name=managed-account-S-1-5-21-1327559124-232896021-3640454735-1119, could not be updated because the current user is not a Farm Administrator.



I think the web service runs the code with another user but I can't figure out why and with which user.


P.S. I've also set RemoteAdministratorAccessDenied to false with the same result.


Thank you,


Marian








0 commentaires:

Enregistrer un commentaire