Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to use an Event Receiver on a List to create a Managed Path with Wildcard-inclusion in the parent WebApplication. I tried to handle it with the following code (reduced to show the idea)

SPSecurity.RunWithElevatedPrivileges(
  () =>
  {
    using (var site = new SPSite(properties.SiteId))
    {
      var semester = new Semester(properties.ListItem);

      var webApplication = site.WebApplication;
      webApplication.Prefixes.Add(semester.UrlPart, SPPrefixType.WildcardInclusion);
      webApplication.Update(true);
    }
  });

If the code comes to Prefixes. And it will throw a SecurityException. The SharepointWebSite-Account is far away from least privilege at the moment (DB-Sysadmin, Local Admin, Farm Admin), but it refuses to perform my task.

I just tried to accomplish my Task with powershell logged on as the user in question - and it works - so the user privileges seem not to be the Problem.

For clearification: it's an asynchronous on ItemAdded Event-Receiver.

I found something in the logs, but as i said from Powershell it works with that user:

08/24/2012 13:46:16.80 w3wp.exe (0x13EC)
0x12C8 SharePoint Foundation Topology
7f7y High Adding a new WildcardInclusion site prefix with the path SoSe to the web application MiscWebApp. efa9c69b-9634-90de-f417-1b3bf5bf9325

08/24/2012 13:46:16.80 w3wp.exe (0x13EC)
0x12C8 SharePoint Foundation Topology
8dyu High The SPPersistedObject, SPWebApplication Name=MiscWebApp, could not be updated because the current user is not a Farm Administrator. efa9c69b-9634-90de-f417-1b3bf5bf9325

Can anybody help?

share|improve this question
    
If the user performing the list operation has sufficient right have you then tried to remove the RunWithElevatedPrivileges? This cause the code to run as AppPool account which hopefully isn't farm admin –  Per Jakobsen Aug 24 '12 at 22:12
add comment

3 Answers 3

Most likely, the Application Pool Identity for the content web application is not the same as the App Pool Identity for the Central Administration web application.

I would suggest moving the list to the Central Administration site collection. That site collection is just like any other. :)

share|improve this answer
add comment

Can you try it this way and let me know if it fixes the issue:

var site = SPContext.Current.Site;
var currentWebApplication = SPContext.Current.Site.WebApplication;
SPSecurity.RunWithElevatedPrivileges(
  () =>
  {
    using (var elevatedSite = new SPSite(site.ID))
    {
      var semester = new Semester(properties.ListItem);
      var webApplication = elevatedSite.WebApplication;
      webApplication.Prefixes.Add(semester.UrlPart, SPPrefixType.WildcardInclusion);
      webApplication.Update(true);
    }
  });
share|improve this answer
    
Besides that SPContext.Current is null in this EventReceiver (it's an asynchronous one), this is just what my code does ... –  Grumbler85 Aug 24 '12 at 11:46
add comment

First thing comes to mind is have you put your dll in the gac?

also look at this as its similar issue:

http://stackoverflow.com/questions/8588675/sharepoint-event-receiver-not-working

EDIT

SPSecurity.RunWithElevatedPrivileges( 
  () => 
  { 
    using (var site = new SPSite(properties.SiteId)) 
    { 
      var semester = new Semester(properties.ListItem); 

      var webApplication = site.WebApplication; 

      webApplication.AllowUnsafeUpdates = true;

      webApplication.Prefixes.Add(semester.UrlPart, SPPrefixType.WildcardInclusion); 
      webApplication.Update(true); 

      webApplication.AllowUnsafeUpdates = false;
    } 
  }); 

Iv just added AllowUnsafeUpdates when your updating to see if it makes a difference!

hope it helps :)

share|improve this answer
    
I struggeled with that for some time, but yes it is in GAC. I connected the VS Debugger and the code is called, but runs into the security exception. –  Grumbler85 Aug 24 '12 at 8:35
    
is there any way you can post the full error? do you have eventViewer or use uls technet.microsoft.com/en-us/library/ff463595.aspx just so i could give you a more specific answer –  ali Sharepoint Aug 24 '12 at 9:30
    
I added the logs to the original post. –  Grumbler85 Aug 24 '12 at 11:53
    
I dont know if this would make any difference to you but you can try my edit! –  ali Sharepoint Aug 24 '12 at 12:48
    
I tried to, but the Problem here is, that webApplication is of Type SPApplication, which has no AllowUnsafeUpdates Property. As i see it in the Moment i have the Chance to do a real impersonation (which i don't like, since i have to store the Password or allow Delegation) or i use an external Management Service, which handles my Task. –  Grumbler85 Aug 27 '12 at 6:20
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.