views:

433

answers:

2

Hello everyone,

I am using SharePiont Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5. I am wondering whether SharePoint has any means to set current user to be some specific user? For example, I want to set the user to be administrator automatically when people connects from a specific IP address to grant such people high privilege. Another example is when people connects my sie using special connection string, like http://mysite/default.aspx?specialtestuser=foo, then I will set current user to be foo. Appreciate if any code samples to reference?

thanks in advance, George

+2  A: 

Hello,

In Sharepoint you can use impersonation to execute code in place of a specific user. You can also use this technique to run some section of your code with higher priviledge (better than giving full high priviledge to a user). Here just 2 links but if you search the net for Sharepoint and Impersonation you will find more links.

MSDN on impersonation and other tricks

Impersonation in Sharepoint 2007

I hope this will help


Here another link that propose to set up some HTTP module and that looks a little like you want to do : siteminder and sharepoint 2007

But I never tried this out so I can't help you much more.

FrenchData
The samples you provided will impersonate the current user with another user. But what I want to do is to set the current user from anonymous to some other specific user, and my requirement is different from impersonate. Any ideas for my requirements?
George2
In more details, I want to switch from anonymous to another user, not impersonate as another user, for example, on the top right corner of UI, user name foo or administrator will be displayed other than anonymous. Any ideas how to implement?
George2
It looks like automatically authenticate a user if URL contains special parameter or from special IP address.
George2
BTW: I am using Forms authentication, not sure whether in Forms authentication in SharePoint, there are any ways to set the anonymous user to someone based on some custom defined rules (e.g. IP address or http parameter)?
George2
Ok. Perhaps you can look in the global.asax or other configuration files of your Sharepoint but this would be something very hard to maintain as global.asax can be replaced in case of upgrade or other. Besides thsi I have no more idea currently
FrenchData
Thanks, question answered!
George2
+2  A: 

SharePoint 2007 fully supports the .NET Provider model, so you can utilize the MembershipProvider model (the SharePoint built-in provider is the LdapMembershipProvider and LdapRoleProvider), which supports the forms based as well as any custom authentication/authorization architecture. You can set the current user from the Membership global object. My caveat would be to use the Membership and Roles object completely throughout your code if you choose this approach.

Nishant's blog is pretty useful for anything MOSS and AD related, and has this post: http://blogs.technet.com/nishants/archive/2009/05/22/how-to-configure-forms-based-authentication-active-directory-ldapmembership.aspx

code4life
Thanks! It is a great document targeting to AD based Forms authentication. But I am not using AD, but using a custom database to store user name and password. Any reference samples similar to my requirements?
George2
Yep, it looks like you need to customize the MembershipProvider
maplpro
Thanks you man!
George2
code4life