开发者

Using ASP.NET Role Provider from Non Web Application (Timer Job) to check Role Membership

I am using this code in a SharePoint web part, that checks if a user is in a role (for Forms Based Authenticated sites).

foreach (stri开发者_开发技巧ng role in System.Web.Security.Roles.GetAllRoles())
  foreach (string user in System.Web.Security.Roles.GetUsersInRole(role))

I then compare usernames for the existing users in the role, and the username (as a string) I am trying to authorize. And it works fine, as expected, as long as the Role provider is setup for the web application.

However, I also have a timer job that is used to process incoming emails sent to the smtp server and relayed locally to the smtp drop folder (C:\inetpub\mailroot\drop). The timer job then reads the email from the drop folder, and parses/processes it. To identity the user sending the email, I take the "from address" and do a lookup to the sharepoint site to get the user's identity using SPUtility.

But, I need to check if the user is in a role specified by that web site's FBA Role Provider. The role provider details are black box, unknown and can be changed at run time, so I have to use the role provider built-in functionality, ie. Roles.GetAllRoles, Roles.GetUsersInRole(x). (I can't go directly to the database or other behind the scenes data source). I do however know the address of the website that I need to authorize the user against from the job timer.

But, System.Web.Security.Roles.GetAllRoles() is not accessible to the job timer because its not an asp.net web application (actually part of the OWSTIMER.exe windows service).

So, How do I check if a "loginname" is a member of a Role from within a Job Timer?

NOTE: This question could also be asked completely leaving SharePoint out, and assuming that I want to check a "loginname" from within a Windows Service or WinForms Application. I basically need to check if a user is in a FBA Role (RoleProvider specified in an asp.net 2.0-3.5 web application's web.config settings), from a source that is not the windows application where the role provider is defined and accessible.

Also, I can't use a web service since the goal is to only have a SharePoint Web Part and SharePoint Job Timer.


You're not specifying your SharePoint version, so I'll assume you're talking about SharePoint 2007 here. However, the same principle would apply to SharePoint 2010.

The OWSTIMER.exe file is stored in 12hive\bin. You can create an OWSTIMER.exe.config file in the same folder and register your role and membership providers in that file the same way you would do it in a web.config file.

For an example, take a look at this article http://msdn.microsoft.com/en-us/library/bb977430(v=office.12).aspx (the interesting part is in the topic 'alerts')

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜