tags:

views:

73

answers:

1

We have an archive site that is an exact copy of the "live" site, but uses a different service account. I have built an EditControlBlock extension that redirects a user to a page in the _layouts folder. The page has some text on it and an Ok button.

Edit: The SPWeb i am trying to use is in a different WebApplication. I am trying to move file x to the archive site.

When the Ok buttons is clicked, it should execute the following code:

using (var archive = new SPSite(archiveurl, SPContext.Current.Web.CurrentUser.UserToken))
{
  using (var newsArchive = archive.RootWeb.Webs[SPContext.Current.Web.Name])
  {
    //move file
  }
}

The weird thing is, it breaks on line 2: using (var newsArchive = archive.RootWeb.Webs[SPContext.Current.Web.Name]) Which is weird, because the first line DOES work. The error I get is:

login failed for user x on database y

Anyone have an idea here? Is code on a page derived from LayoutsPageBase always run as the web app apppool account or something?

+1  A: 

I have set the Database ights for the moment on the target database. I had to make the apppool user of the source web app a member of the db_owner group in the target database. Not to sure if this is the way to go. Anyone with a better idea please tell me.

Colin
+1 That makes sense and is the best idea I can think of!
Alex Angas
What about Web Services ?
Kusek
THis should be possible seeing as all code is ran on the same farm. It should work. using the Web services when you can use the API is IMHO a major workaround (i.e. you change code to workaround an issue which as far i can tell is a configuration issue)
Colin
"THis should be possible " = the code without web services.
Colin