开发者

Design question about SPSecurity.RunWithElevatedPriviledges in multi-tiered design

开发者 https://www.devze.com 2022-12-11 18:03 出处:网络
I have a question re: performance and design. Crux of the problem is: do I wrap RunWithElevatedPriviledges around a sequence of methods all requiring its use (but the call is in the wrong layer), do I

I have a question re: performance and design. Crux of the problem is: do I wrap RunWithElevatedPriviledges around a sequence of methods all requiring its use (but the call is in the wrong layer), do I call it each time in the appropriate later.

I am refactoring code that initially had 2 layers (front-end & database).

I've now split this out into 4 layers

  • Front-end (Sharepoint)
  • Service-layer
  • Data-access-layer
  • Database

Now, owing to a prescribed configuration I need to throw RunWithElevatedPriviledges around the sql queries so that the app pool can authenticate against the database (please dont post comments telling me this is a bad idea, I realise this is a terrible idea but it's not my call).

For each data call I will have to be in elevated privileges. For my mind, this should happen in the Service layer.开发者_开发技巧 The FE should have no clue about this requirement and neither should the Data Access Layer. However, the service layer is called multiple times to populate a series of dropdowns

i.e.

userlistbox.datasource = MyService.GetUsers(); //Returns an iEnumerable object
citylistbox.datasource = MyService.GetCities(currentRegion); //Returns an iEnumerable object

etc.

The unrefactored version wraps all of these calls with the elevated privileges. My sense is that it will be slightly less performant to push this into the service layer but that it's a better design.

Thoughts? And please, no bashing the constraints I can't do anything about.


Better in the Service layer than in the Front End. Maybe you could pass the SPSecurity.CodeToRunElevated Delegate?

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.codetorunelevated.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号