views:

42

answers:

2

Hello All:

How to create a sharepoint 2007 site by impersonating with custom account, so that it wont show login prompt box

A: 

Use SPSite constructor where you pass SPUserToken object To get token of some user, use SPWeb.AllUsers["userLoginName"].UserToken

Janis Veinbergs
Thanks Janis for your response,In my case I dont want sharepoint site to prompt for login, my site is accesible to anonymous users, so when I am impersonating using 'SPWeb.AllUsers["userLoginName"].UserToken' it is prompting for login. How to impersonate without that login prompt.Thanks in advance
Uma Maheshwar
I don't understand. How would it prompt for a login when you do things in code behind? Where are you putting that code in and what do you want to do?
Janis Veinbergs
A: 

I think that to be able get a user token you should be running your code with elevated priviledges and that might be why is pompting for login (beacuse the anonimous user doesnt have permissions to get another users token)

Example

 SPSecurity.RunWithElevatedPrivileges(delegate()
            {           
   //is important that you instantiate your SPSite object within you elevated code        
              using (SPSite oSite = new SPSite("your site URL"))
                    {

                        using (SPWeb oWeb = "your web")
                        {
                          //your code to run elevated 
                        }
                    }
            });
Renzo

related questions