Question

My issue seems to be related to permissions, but I am not sure how to solve it.

In the FeatureActivated event of one of my features I am calling out to a class I created for managing webconfig entries using the SPWebConfigModification class. The class reads up an xml file that I have added to the mapped Layouts folder in the project.

When I deploy the .wsp to my Sharepoint server everything gets installed fine, but when the FeatureActivated event runs it throws a 503 error when attempting to access the xml file.I am deploying the .wsp remotely using a powershell script and I have the powershell, the iisapp pool and the owstimer.exe all using the same domain administrative user.

I assumed the issue was that the FeatureActivated event code was being run within the scope of the OWSTIMER.exe so changed the logon of the service to a domain user that has administrative access to the server to see if that would solve the problem, but no matter what I am getting the 503.

I have traced out the URL to the xml file and pasted that into IE and I am getting back the xml without issue from the server once its copied.

Can anyone give me any idea where to look to figure out why the FeatureActivated event code can't seem to get to the XML file on the server?

Below is the code in my class that is being called from the FeatureActivated event to read the xml.

_contentservice = ContentService;

WriteTraceMessage("Getting SPFeatureProperties", TraceSeverity.Medium, 5);

_siteurl = properties.Definition.Properties["SiteUrl"].Value;
_foldername = properties.Definition.Properties["FolderName"].Value;
_filename = properties.Definition.Properties["FileName"].Value;
_sitepath = properties.Definition.Properties["SitePath"].Value;

WriteTraceMessage("Loading xml from layouts for configuration keys", TraceSeverity.Medium, 6);

xdoc = new XDocument();
XmlUrlResolver resolver = new XmlUrlResolver();
XmlReaderSettings settings = new XmlReaderSettings();

StringBuilder sb = new StringBuilder();
                 sb.Append(_siteurl).Append("_layouts").Append("/").Append(_foldername).Append("/").Append(_filename);

WriteTraceMessage("Path to XML: " + sb.ToString(), TraceSeverity.Medium, 7);
WriteTraceMessage("Credentials for xml reader: " + CredentialCache.DefaultCredentials.ToString(), TraceSeverity.Medium, 8);

resolver.Credentials = CredentialCache.DefaultCredentials; //this the issue might be here
settings.XmlResolver = resolver;
xdoc = XDocument.Load(XmlReader.Create(sb.ToString(), settings));
Was it helpful?

Solution

I finally punted on this issue because I discovered that while adding the -Force switch to the Enable-SPFeature command did use a different process to activate the feature when adding a solution it did not work when updating a solution. Ultimately I just changed my XDocument.Load() to use a TextReader instead of a URI. The xml file will always be available when deploying the WSP because it is part of the package so there is no reason to use IIS and a webrequest to load up the xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top